Repository navigation
keep state inside SearchDelegate #43582
Copy link
Copy link
Closed
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
I have FutureBuilder>>ListView widgets Inside @OverRide buildResults(BuildContext context) method. I navigate to a new screen on list view item tap. but when i pop from the new screen the future is called again. Also i have pagination in the main list view, so when the user tap on item 100 for ex. after popping from the new screen, the main listview it will rebuild from the beginning
class DataSearch extends SearchDelegate<String>{
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.clear),
onPressed: () {
query = '';
})
];
}
@override
ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(
hintStyle: TextStyle(color: theme.primaryTextTheme.title.color)),
primaryColor: theme.primaryColor,
primaryIconTheme: theme.primaryIconTheme,
primaryColorBrightness: theme.primaryColorBrightness,
primaryTextTheme: theme.primaryTextTheme,
textTheme: theme.textTheme.copyWith(
title: theme.textTheme.title
.copyWith(color: theme.primaryTextTheme.title.color)));
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
onPressed: () {
close(context, null);
});
}
@override
Widget buildResults(BuildContext context) {
SearchProvider searchProvider =
Provider.of<SearchProvider>(context, listen: false);
return query.isEmpty == true ? Container() : FutureBuilder(
future: searchProvider.fetchData(query),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: SpinKitHourGlass(
color: Colors.greenAccent,
));
break;
default:
if (snapshot.hasError) {
return Center(child: Text("Error: ${snapshot.error}"));
} else {
return Consumer<SearchProvider>(
builder: (context, provider, child) => ImageList(
models: snapshot.data,
isSearch: true,
),
);
}
}
});
}
@override
Widget buildSuggestions(BuildContext context) {
return Container();
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
mohamed6996 commentedon Oct 27, 2019
I have tried to wrap the Futurebuilder widget inside a statefull widget and use AutomaticKeepAliveClientMixin but in vain
gopalkriagg commentedon Dec 19, 2019
Would like to see this feature get implemented! Thanks!
SalehHub commentedon Jan 15, 2020
This is really important to us
I hope it gets implemented
JigneshWorld commentedon Apr 13, 2020
Any possible workaround for this?
ixsans commentedon Aug 18, 2020
I also facing this issue. Hopefully this can be implemented.
pankaj-nayak commentedon Aug 21, 2020
I am also facing this issue. I am passing a list to search delegate , and if query does not have the item in the list, I need to add this to the list and reload the list again . Do we have any kind of "state" in search delegate?
DJ-Raven commentedon Sep 25, 2020
ctrl click on SearchDelegate it will open class material\search.dart
change bool get maintainState => false;
to bool get maintainState => true;
yaroaxito commentedon Oct 15, 2020
I am also facing this issue. Please implement this.
zhanghsgithub commentedon Oct 30, 2020
我一直以为是我学艺不精,原来是源码有问题^_^!
ivanchaukn commentedon Jan 27, 2021
I'm having the same issue too!
HendricManenga commentedon Feb 4, 2021
I have the same issue
AmG2000 commentedon Feb 10, 2021
I also have the same issue. Is there an alternative to copying search.dart?
7 remaining items
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate
fix: add parameter to maintainState of SearchDelegate (#152444)
fix: add parameter to maintainState of SearchDelegate (flutter#152444)
github-actions commentedon Aug 20, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.fix: add parameter to maintainState of SearchDelegate (flutter#152444)