@@ -40,7 +40,7 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
4040 _searchController.addListener (() {
4141 setState (() {
4242 _isSearching = _searchController.text.length > 0 ;
43- _getData ();
43+ // _getData();
4444 });
4545 });
4646 WidgetsBinding .instance.addPostFrameCallback ((_) {
@@ -87,46 +87,75 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
8787 ),
8888 ];
8989 },
90- body: Builder (builder: (context) {
91- if (_isSearching) {
92- return FutureBuilder <Map <String ,dynamic >>(
93- key: UniqueKey (),
94- future: _imagesFuture,
95- builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
96- if (imagesSnapshot.hasData){
97- print ("Images: ${imagesSnapshot .data }" );
98- if (imagesSnapshot.data['stat' ] == 'fail' ) {
90+ body: RefreshIndicator (
91+ displacement: 20 ,
92+ notificationPredicate: (notification) {
93+ return notification.metrics.atEdge;
94+ },
95+ onRefresh: () {
96+ _getData ();
97+ return Future .delayed (Duration (milliseconds: 1000 ));
98+ },
99+ child: Builder (builder: (context) {
100+ if (_isSearching) {
101+ return FutureBuilder <Map <String ,dynamic >>(
102+ key: UniqueKey (),
103+ future: _imagesFuture,
104+ builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
105+ if (imagesSnapshot.hasData){
106+ if (imagesSnapshot.data['stat' ] == 'fail' ) {
107+ return Center (
108+ child: Text (appStrings (context).categoryImageList_noDataError),
109+ );
110+ }
111+ var images = imagesSnapshot.data['result' ]['images' ];
112+ var nbImages = images.length;
113+ return Column (
114+ children: [
115+ _imageGrid (images),
116+ Center (
117+ child: Container (
118+ padding: EdgeInsets .all (10 ),
119+ child: Text (appStrings (context).imageCount (nbImages), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
120+ ),
121+ ),
122+ ],
123+ );
124+ } else {
99125 return Center (
100- child: Text ( appStrings (context).categoryImageList_noDataError ),
126+ child: CircularProgressIndicator ( ),
101127 );
102128 }
103- var images = imagesSnapshot.data['result' ]['images' ];
104- var nbImages = images.length;
105- return RefreshIndicator (
106- displacement: 20 ,
107- notificationPredicate: (notification) {
108- return notification.metrics.atEdge;
109- },
110- onRefresh: () {
111- setState (() {
112- print ("refresh" );
113- });
114- return Future .delayed (Duration (milliseconds: 1000 ));
115- },
116- child: SingleChildScrollView (
117- physics: NeverScrollableScrollPhysics (),
118- child: Column (
119- children: [
120- _imageGrid (images),
121- Center (
122- child: Container (
123- padding: EdgeInsets .all (10 ),
124- child: Text (appStrings (context).imageCount (nbImages), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300)),
125- ),
126- ),
127- ],
129+ },
130+ );
131+ }
132+ return FutureBuilder <Map <String ,dynamic >>(
133+ key: UniqueKey (),
134+ future: _albumsFuture, // Albums of the list
135+ builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
136+ if (albumSnapshot.hasData){
137+ if (albumSnapshot.data['stat' ] == 'fail' ) {
138+ return Container (
139+ padding: EdgeInsets .all (10 ),
140+ child: Text (albumSnapshot.data['result' ]),
141+ ); //appStrings(context).categoryMainEmpty
142+ }
143+ var albums = albumSnapshot.data['result' ]['categories' ];
144+ int nbPhotos = 0 ;
145+ albums.forEach ((cat) => nbPhotos+= cat["total_nb_images" ]);
146+ albums.removeWhere ((category) => (
147+ category["id" ].toString () == _rootCategory
148+ ));
149+ return Column (
150+ children: [
151+ _albumGrid (albums),
152+ Center (
153+ child: Container (
154+ padding: EdgeInsets .all (10 ),
155+ child: Text (appStrings (context).imageCount (nbPhotos), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
156+ ),
128157 ),
129- ) ,
158+ ] ,
130159 );
131160 } else {
132161 return Center (
@@ -135,59 +164,8 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
135164 }
136165 },
137166 );
138- }
139- return FutureBuilder <Map <String ,dynamic >>(
140- key: UniqueKey (),
141- future: _albumsFuture, // Albums of the list
142- builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
143- if (albumSnapshot.hasData){
144- //print(albumSnapshot.data);
145- if (albumSnapshot.data['stat' ] == 'fail' ) {
146- return Container (
147- padding: EdgeInsets .all (10 ),
148- child: Text (albumSnapshot.data['result' ]),
149- ); //appStrings(context).categoryMainEmtpy
150- }
151- var albums = albumSnapshot.data['result' ]['categories' ];
152- int nbPhotos = 0 ;
153- albums.forEach ((cat) => nbPhotos+= cat["total_nb_images" ]);
154- albums.removeWhere ((category) => (
155- category["id" ].toString () == _rootCategory
156- ));
157- return RefreshIndicator (
158- displacement: 20 ,
159- notificationPredicate: (notification) {
160- return notification.metrics.atEdge;
161- },
162- onRefresh: () {
163- setState (() {
164- print ("refresh" );
165- });
166- return Future .delayed (Duration (milliseconds: 1000 ));
167- },
168- child: SingleChildScrollView (
169- physics: NeverScrollableScrollPhysics (),
170- child: Column (
171- children: [
172- _albumGrid (albums),
173- Center (
174- child: Container (
175- padding: EdgeInsets .all (10 ),
176- child: Text (appStrings (context).imageCount (nbPhotos), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300)),
177- ),
178- ),
179- ],
180- ),
181- ),
182- );
183- } else {
184- return Center (
185- child: CircularProgressIndicator (),
186- );
187- }
188- },
189- );
190- }),
167+ }),
168+ ),
191169 ),
192170 ),
193171 floatingActionButton: widget.isAdmin ? FloatingActionButton (
@@ -199,7 +177,7 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
199177 }
200178 ).whenComplete (() {
201179 setState (() {
202- print ( 'refresh' );
180+ _getData ( );
203181 });
204182 });
205183 },
0 commit comments