I am working on an application that uses BLoC for state management, this is the situation:
I have a SearchDelegate that has a model as DataType (SearchDelegate<SearchModel>
), this SearchDelegate consumes an API to get SearchResults. When I onTap()
in one of the results I take the information in a variable with the name of searchResults
after this I use close(context, result)
and navigate to the new page, in this page I want to use all the information from that model, the problem is that I don't know how to do that.
The code for my BuildResults when someone taps in one of the options
onTap: () {
final searchResult = SearchModel(
position: LatLng( search.lat[0], search.lng[1]),
name: search.text,
description: search.placeName
);
close(context, result);
pushToPage(context, const RoutePage());
},
How can I pass this parameter and work with them in a UI with Bloc?
you can make a required parameter in your RoutePage widget and then while navigating to the RoutePage screen you can pass the same
// RoutePage widget class constructor
const RoutePage({Key? key, required this.subjectModel})
: super(key: key);
final SearchModel searchModel;
// while navigation
onTap: () {
final searchResult = SearchModel(
position: LatLng( search.lat[0], search.lng[1]),
name: search.text,
description: search.placeName
);
close(context, result);
pushToPage(context, RoutePage(searchModel:searchResult));
},