I get data from the cache. When clicking the search button showing RefreshProgressIndicator
and then showing material_search
page. Is it possible to remove loading on if(snapshot.hasdata){}else{loading widget}
without null
error message? If it is impossible, then how to use 'StreamBuilder' inside 'MaterialSerach' page? I used MaterialSearch plugin.
builder: (BuildContext context) {
return Material(
child: StreamBuilder(
stream: _subCategoryBloc.subCategory,
builder: (context, AsyncSnapshot<List<SubCategorie>> snapshot) {
if (snapshot.data != null) {
return MaterialSearch<String>(
barBackgroundColor: Color(0xFFEDB111),
placeholder: 'Search',
results: snapshot.data
.map((value) => MaterialSearchResult<String>(
value: value.subCategoryName,
subText: "${value.noOfMembers} Vendors",
categoryId: value.categoryId,
categoryName: value.categoryName,
subId: value.id,
text: value.subCategoryName))
.toList(),
filter: (dynamic value, String criteria) {
return value.toLowerCase().trim().contains(
RegExp(r'' + criteria.toLowerCase().trim() + ''));
},
onSubmit: (String value) {
Navigator.of(context).pop(value);
},
);
} else {
return Center(
child: RefreshProgressIndicator(
backgroundColor: Color(0xFFFFFFFF)));
}
}),
);
});
You can try this:
builder: (BuildContext context) {
return Material(
child: StreamBuilder(
stream: _subCategoryBloc.subCategory,
builder: (BuildContext context, processingSnapshot) {
switch (processingSnapshot.connectionState) {
case ConnectionState.active:
case ConnectionState.done:
if (processingSnapshot.hasData) {
return MaterialSearch<String>(
barBackgroundColor: Color(0xFFEDB111),
placeholder: 'Search',
results: snapshot.data
.map((value) => MaterialSearchResult<String>(
value: value.subCategoryName,
subText: "${value.noOfMembers} Vendors",
categoryId: value.categoryId,
categoryName: value.categoryName,
subId: value.id,
text: value.subCategoryName))
.toList(),
filter: (dynamic value, String criteria) {
return value.toLowerCase().trim().contains(
RegExp(r'' + criteria.toLowerCase().trim() + ''));
},
onSubmit: (String value) {
Navigator.of(context).pop(value);
},
);
} else {
return Center(
child: RefreshProgressIndicator(
backgroundColor: Color(0xFFFFFFFF)));
}
break;
default:
return CircularProgressIndicator();
}
},
}),
);
});
User contributions licensed under CC BY-SA 3.0