Skip to content

Commit f33737e

Browse files
committed
fixed error when starting search
1 parent 57cf09d commit f33737e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/views/RootCategoryViewPage.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
3838
super.initState();
3939
_rootCategory = "0";
4040
_searchController.addListener(() {
41-
_getData();
4241
setState(() {
4342
_isSearching = _searchController.text.length > 0;
43+
_getData();
4444
});
4545
});
4646
WidgetsBinding.instance.addPostFrameCallback((_) {
4747
API.uploader = Uploader(context);
4848
});
49+
_getData();
4950
}
5051
@override
5152
void dispose() {
@@ -89,9 +90,11 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
8990
body: Builder(builder: (context) {
9091
if(_isSearching) {
9192
return FutureBuilder<Map<String,dynamic>>(
92-
future: _imagesFuture, // Albums of the list
93+
key: UniqueKey(),
94+
future: _imagesFuture,
9395
builder: (BuildContext context, AsyncSnapshot imagesSnapshot) {
9496
if(imagesSnapshot.hasData){
97+
print("Images: ${imagesSnapshot.data}");
9598
if(imagesSnapshot.data['stat'] == 'fail') {
9699
return Center(
97100
child: Text(appStrings(context).categoryImageList_noDataError),
@@ -134,9 +137,11 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
134137
);
135138
}
136139
return FutureBuilder<Map<String,dynamic>>(
140+
key: UniqueKey(),
137141
future: _albumsFuture, // Albums of the list
138142
builder: (BuildContext context, AsyncSnapshot albumSnapshot) {
139143
if(albumSnapshot.hasData){
144+
//print(albumSnapshot.data);
140145
if(albumSnapshot.data['stat'] == 'fail') {
141146
return Container(
142147
padding: EdgeInsets.all(10),
@@ -147,7 +152,7 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
147152
int nbPhotos = 0;
148153
albums.forEach((cat) => nbPhotos+=cat["total_nb_images"]);
149154
albums.removeWhere((category) => (
150-
category["id"].toString() == _rootCategory
155+
category["id"].toString() == _rootCategory
151156
));
152157
return RefreshIndicator(
153158
displacement: 20,
@@ -279,5 +284,4 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
279284
},
280285
);
281286
}
282-
283287
}

lib/views/components/textfields.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ class TextFieldSearch extends StatelessWidget {
108108
),
109109
),
110110
),
111+
if(controller.text.isNotEmpty)
112+
GestureDetector(
113+
onTap: () => controller.clear(),
114+
child: Padding(
115+
padding: const EdgeInsets.symmetric(horizontal: 8.0),
116+
child: Icon(Icons.close, color: _theme.iconTheme.color),
117+
),
118+
),
111119
],
112120
),
113121
);

0 commit comments

Comments
 (0)