Hello i want to send my model class object to next screen previously i do it like this first i declare object in the second screen where i want to naviagte个
class ContactsDetail extends StatelessWidget {
ContactModel contactDetail;
ContactsDetail({Key? key, required this.contactDetail}) : super(key: key);
Then in navigator i passed the argument
onTap: () async {
Navigator.of(context).push(MaterialPageRoute<void>(builder: (BuildContext context) {
return ContactsDetail(
contactDetail: contactlist[index],);
},
));
},`enter code here`
Which works perfectly, Now i am working with name routes and i want to send the whole model of current index data same as i do above but i am unable to do this Now here is my routes .个
Route<dynamic> generateRoute(RouteSettings settings){
switch(settings.name)
{
case LoginScreen.routeName:
return MaterialPageRoute(builder: (context) => const LoginScreen());
case TourDetailScreen.routeName:
return MaterialPageRoute(builder: (context) => TourDetailScreen());
default:
return errorRoute();
}
}
And here is the class to which i want to send data
class TourDetailScreen extends StatelessWidget {
static const routeName = 'tourist_detail_screen';
TourModel tourDetails;
TourDetailScreen({Key? key,required this.tourDetails}) : super(key: key);
and this is main
MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: TouristHomeScreen.routeName,
onGenerateRoute: (settings) => generateRoute(settings),
),