skip to Main Content

navigation to detailscreen with data
Navigator.of(context).pushNamed(‘/detailScren’, arguments: "data");

DetailScreen: here i’m getting null from Modal Routes.

class DetailScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
      final arguments = ModalRoute.of(context)!.settings.arguements;
      print(arguments); //  always null
      return Scaffold(
        body: Container(),
      );
  }

Below is App code in main.dart

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale,
      title: Strings.appName,
      theme: CustomTheme.lightTheme,
      onGenerateRoute: AppRoutes.generateRoute,
      home: MainScreen(),
    );
  }

Arguments passing and receiving.

2

Answers


  1. You wrote "ModalRoute.of(context)!.settings.arguements;", arguements, instead of arguments.

    Login or Signup to reply.
  2. The onGenerateRoute approach is different from passing arguments directly to the route. You should manage arguments directly inside onGenerateRoute: https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments#alternatively-extract-the-arguments-using-ongenerateroute

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search