@@ -29,6 +29,7 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
2929 TextEditingController _searchController = TextEditingController ();
3030 ScrollController _scrollController = ScrollController ();
3131 bool _isSearching = false ;
32+ final FocusNode _focus = FocusNode ();
3233
3334 Future <Map <String ,dynamic >> _albumsFuture;
3435 Future <Map <String ,dynamic >> _imagesFuture;
@@ -37,11 +38,10 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
3738 void initState () {
3839 super .initState ();
3940 _rootCategory = "0" ;
40- _searchController.addListener (() {
41- setState (() {
42- _isSearching = _searchController.text.length > 0 ;
43- //_getData();
44- });
41+ _focus.addListener (() {
42+ if (! _focus.hasFocus) {
43+ setState (() {});
44+ }
4545 });
4646 WidgetsBinding .instance.addPostFrameCallback ((_) {
4747 API .uploader = Uploader (context);
@@ -64,7 +64,7 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
6464 return Scaffold (
6565 body: GestureDetector (
6666 onTap: () {
67- FocusScope . of (context) .unfocus ();
67+ _focus .unfocus ();
6868 },
6969 child: NestedScrollView (
7070 controller: _scrollController,
@@ -84,6 +84,14 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
8484 ),
8585 AppBarExpandableSearch (
8686 textController: _searchController,
87+ onTap: () {},
88+ focusNode: _focus,
89+ onSubmit: (string) {
90+ setState (() {
91+ _isSearching = _searchController.text.length > 0 ;
92+ _getData ();
93+ });
94+ },
8795 ),
8896 ];
8997 },
@@ -96,27 +104,64 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
96104 _getData ();
97105 return Future .delayed (Duration (milliseconds: 1000 ));
98106 },
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+ child: SingleChildScrollView (
108+ child: Builder (builder: (context) {
109+ if (_isSearching) {
110+ return FutureBuilder <Map <String ,dynamic >>(
111+ key: UniqueKey (),
112+ future: _imagesFuture,
113+ builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
114+ if (imagesSnapshot.hasData){
115+ if (imagesSnapshot.data['stat' ] == 'fail' ) {
116+ return Center (
117+ child: Text (appStrings (context).categoryImageList_noDataError),
118+ );
119+ }
120+ var images = imagesSnapshot.data['result' ]['images' ];
121+ var nbImages = images.length;
122+ return Column (
123+ children: [
124+ _imageGrid (images),
125+ Center (
126+ child: Container (
127+ padding: EdgeInsets .all (10 ),
128+ child: Text (appStrings (context).imageCount (nbImages), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
129+ ),
130+ ),
131+ ],
132+ );
133+ } else {
107134 return Center (
108- child: Text ( appStrings (context).categoryImageList_noDataError ),
135+ child: CircularProgressIndicator ( ),
109136 );
110137 }
111- var images = imagesSnapshot.data['result' ]['images' ];
112- var nbImages = images.length;
138+ },
139+ );
140+ }
141+ return FutureBuilder <Map <String ,dynamic >>(
142+ key: UniqueKey (),
143+ future: _albumsFuture, // Albums of the list
144+ builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
145+ if (albumSnapshot.hasData){
146+ if (albumSnapshot.data['stat' ] == 'fail' ) {
147+ return Container (
148+ padding: EdgeInsets .all (10 ),
149+ child: Text (albumSnapshot.data['result' ]),
150+ ); //appStrings(context).categoryMainEmpty
151+ }
152+ var albums = albumSnapshot.data['result' ]['categories' ];
153+ int nbPhotos = 0 ;
154+ albums.forEach ((cat) => nbPhotos+= cat["total_nb_images" ]);
155+ albums.removeWhere ((category) => (
156+ category["id" ].toString () == _rootCategory
157+ ));
113158 return Column (
114159 children: [
115- _imageGrid (images ),
160+ _albumGrid (albums ),
116161 Center (
117162 child: Container (
118163 padding: EdgeInsets .all (10 ),
119- child: Text (appStrings (context).imageCount (nbImages ), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
164+ child: Text (appStrings (context).imageCount (nbPhotos ), style: TextStyle (fontSize: 20 , color: _theme.textTheme.bodyText2.color, fontWeight: FontWeight .w300,),),
120165 ),
121166 ),
122167 ],
@@ -128,43 +173,8 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
128173 }
129174 },
130175 );
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- ),
157- ),
158- ],
159- );
160- } else {
161- return Center (
162- child: CircularProgressIndicator (),
163- );
164- }
165- },
166- );
167- }),
176+ }),
177+ ),
168178 ),
169179 ),
170180 ),
0 commit comments