@@ -28,7 +28,6 @@ class RootCategoryViewPage extends StatefulWidget {
2828class _RootCategoryViewPageState extends State <RootCategoryViewPage > with SingleTickerProviderStateMixin {
2929 String _rootCategory;
3030 TextEditingController _searchController = TextEditingController ();
31- ScrollController _scrollController = ScrollController ();
3231 bool _isSearching = false ;
3332 final FocusNode _focus = FocusNode ();
3433
@@ -79,119 +78,111 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
7978 ThemeData _theme = Theme .of (context);
8079 return Scaffold (
8180 key: RootCategoryViewPage .rootKey,
82- body: SafeArea (
83- child: GestureDetector (
84- onTap: () {
85- _focus.unfocus ();
81+ body: GestureDetector (
82+ onTap: () {
83+ _focus.unfocus ();
84+ },
85+ child: RefreshIndicator (
86+ onRefresh: () {
87+ setState (() {
88+ _getData ();
89+ });
90+ return Future .delayed (Duration (milliseconds: 1000 ));
8691 },
87- child: RefreshIndicator (
88- onRefresh: () {
89- setState (() {
90- _getData ();
91- });
92- return Future .delayed (Duration (milliseconds: 1000 ));
93- },
94- child: CustomScrollView (
95- slivers: [
96- SliverAppBar (
97- pinned: true ,
98- backgroundColor: Theme .of (context).appBarTheme.backgroundColor,
99- leading: IconButton (
100- onPressed: () {
101- Navigator .of (context).push (
102- MaterialPageRoute (builder: (context) => SettingsPage ()),
103- );
104- },
105- icon: Icon (Icons .settings, color: _theme.iconTheme.color),
106- ),
107- title: Text (appStrings (context).tabBar_albums,
108- style: TextStyle (fontSize: 20 , fontWeight: FontWeight .w500),
109- ),
110- ),
111- AppBarSearch (
112- textController: _searchController,
113- onTap: () {},
114- focusNode: _focus,
115- onSubmit: (string) {
116- setState (() {
117- _isSearching = _searchController.text.length > 0 ;
118- _getData ();
119- });
92+ child: CustomScrollView (
93+ slivers: [
94+ SliverAppBar (
95+ pinned: true ,
96+ backgroundColor: Theme .of (context).appBarTheme.backgroundColor,
97+ leading: IconButton (
98+ onPressed: () {
99+ Navigator .of (context).push (
100+ MaterialPageRoute (builder: (context) => SettingsPage ()),
101+ );
120102 },
103+ icon: Icon (Icons .settings, color: _theme.iconTheme.color),
121104 ),
122- SliverToBoxAdapter (
123- child: Builder (builder: (context) {
124- if (_isSearching) {
125- return FutureBuilder <Map <String ,dynamic >>(
126- key: UniqueKey (),
127- future: _imagesFuture,
128- builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
129- if (imagesSnapshot.hasData){
130- if (imagesSnapshot.data['stat' ] == 'fail' ) {
131- return Center (
132- child: Text (appStrings (context).categoryImageList_noDataError),
133- );
134- }
135- var images = imagesSnapshot.data['result' ]['images' ];
136- var nbImages = images.length;
137- return Column (
138- children: [
139- _imageGrid (images),
140- Center (
141- child: Container (
142- padding: EdgeInsets .all (10 ),
143- child: Text (appStrings (context).imageCount (nbImages), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
144- ),
145- ),
146- ],
147- );
148- } else {
149- return Center (
150- child: CircularProgressIndicator (),
151- );
152- }
153- },
154- );
155- }
105+ title: Text (appStrings (context).tabBar_albums,
106+ style: TextStyle (fontSize: 20 , fontWeight: FontWeight .w500),
107+ ),
108+ ),
109+ AppBarSearch (
110+ textController: _searchController,
111+ onTap: () {},
112+ focusNode: _focus,
113+ onSubmit: (string) {
114+ setState (() {
115+ _isSearching = _searchController.text.length > 0 ;
116+ _getData ();
117+ });
118+ },
119+ ),
120+ SliverToBoxAdapter (
121+ child: Builder (builder: (context) {
122+ if (_isSearching) {
156123 return FutureBuilder <Map <String ,dynamic >>(
157124 key: UniqueKey (),
158- future: _albumsFuture, // Albums of the list
159- builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
160- if (albumSnapshot.hasData){
161- if (albumSnapshot.data['stat' ] == 'fail' ) {
162- return Container (
163- padding: EdgeInsets .all (10 ),
164- child: Text (albumSnapshot.data['result' ]),
165- ); //appStrings(context).categoryMainEmpty
125+ future: _imagesFuture,
126+ builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
127+ if (imagesSnapshot.hasData){
128+ if (imagesSnapshot.data['stat' ] == 'fail' ) {
129+ return Center (
130+ child: Text (appStrings (context).categoryImageList_noDataError),
131+ );
166132 }
167- var albums = albumSnapshot.data['result' ]['categories' ];
168- int nbPhotos = 0 ;
169- albums.forEach ((cat) => nbPhotos+= cat["total_nb_images" ]);
170- albums.removeWhere ((category) => (
171- category["id" ].toString () == _rootCategory
172- ));
133+ var images = imagesSnapshot.data['result' ]['images' ];
134+ var nbImages = images.length;
173135 return Column (
174136 children: [
175- _albumGrid (albums ),
137+ _imageGrid (images ),
176138 Center (
177139 child: Container (
178140 padding: EdgeInsets .all (10 ),
179- child: Text (appStrings (context).imageCount (nbPhotos ), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
141+ child: Text (appStrings (context).imageCount (nbImages ), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
180142 ),
181143 ),
182144 ],
183145 );
184- } else {
185- return Center (
186- child: CircularProgressIndicator (),
187- );
188146 }
147+ return Center (child: CircularProgressIndicator ());
189148 },
190149 );
191- }),
192- ),
193- ],
194- ),
150+ }
151+ return FutureBuilder <Map <String ,dynamic >>(
152+ key: UniqueKey (),
153+ future: _albumsFuture, // Albums of the list
154+ builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
155+ if (albumSnapshot.hasData){
156+ if (albumSnapshot.data['stat' ] == 'fail' ) {
157+ return Container (
158+ padding: EdgeInsets .all (10 ),
159+ child: Text (albumSnapshot.data['result' ]),
160+ ); //appStrings(context).categoryMainEmpty
161+ }
162+ var albums = albumSnapshot.data['result' ]['categories' ];
163+ int nbPhotos = 0 ;
164+ albums.forEach ((cat) => nbPhotos+= cat["total_nb_images" ]);
165+ albums.removeWhere ((category) => (
166+ category["id" ].toString () == _rootCategory
167+ ));
168+ return Column (
169+ children: [
170+ _albumGrid (albums),
171+ Center (
172+ child: Container (
173+ padding: EdgeInsets .all (10 ),
174+ child: Text (appStrings (context).imageCount (nbPhotos), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
175+ ),
176+ ),
177+ ],
178+ );
179+ }
180+ return Center (child: CircularProgressIndicator ());
181+ },
182+ );
183+ }),
184+ ),
185+ ],
195186 ),
196187 ),
197188 ),
0 commit comments