Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot passarguments throughonGenerateRoute() innull-safety version of flutter #79376

Closed
Labels
a: null-safetySupport for Dart's null safety featured: api docsIssues with https://api.flutter.dev/d: examplesSample code and demosf: routesNavigator, Router, and related APIs.found in release: 2.0Found to occur in 2.0frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
@Abhishek0116

Description

@Abhishek0116

What am I trying to do?

As usual, I am trying to sending data from one screen to anotheronGenerateRoute() but I screen does not accept arguments type and showing errorThe argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'.

I also tried to change the argument typeObject? on the receiver screen but now I am not able to extract data fromObject toMap<String, dynamic>. I think both are the same data type but the null-safety version is treated differently. I think this is a bug.

I have seenflutter official documentation for navigate-with-arguments and when I switched to null-safety inInteractive example section then it also showing error. See this screenshot or try it yourself.

Screenshot 2021-03-30 at 20 13 56

It's working properly in the non-null-safety version of flutter

Here's the snippet

RouteGenerator Class

class RouteGenerator {  static Route<dynamic> generateRoute(RouteSettings settings) {    // Getting arguments passed while calling Navigator.pushNamed    final args = settings.arguments;    switch (settings.name) {      case HomeScreen.routeName:        return MaterialPageRoute(          builder: (context) => HomeScreen(),        );      case LoginScreen.routeName:        return MaterialPageRoute(          builder: (context) => LoginScreen(),        );      case VerifyFirebaseOtpScreen.routeName:        return MaterialPageRoute(          builder: (context) => VerifyFirebaseOtpScreen(data: args), // Here is the error: The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'.        );      case AboutScreen.routeName:        return MaterialPageRoute(          builder: (context) => AboutScreen(),        );      default:        return MaterialPageRoute(          builder: (context) => Scaffold(            body: SafeArea(              child: Center(                child: Text('No route defined for ${settings.name}'),              ),            ),          ),        );    }  }}

VerifyFirebaseOtpScreen

class VerifyFirebaseOtpScreen extends StatelessWidget {  static const String routeName = '/verify_firebase_otp_screen';  final Map<String, dynamic> data;  const VerifyFirebaseOtpScreen({    Key? key,    required this.data,  }) : super(key: key);  @override  Widget build(BuildContext context) {    return GestureDetector(      onTap: () {        FocusScope.of(context).unfocus();      },      child: Scaffold(        body: Center(          child: SingleChildScrollView(            padding: const EdgeInsets.all(8.0),            child: Container(              width: double.infinity,              child: VerifyFirebaseOtpScreenDataSection(                mobile: '${data['mobile']}',              ),            ),          ),        ),      ),    );  }}
Logs
abhishekkumar@Abhisheks-MacBook-Air ~ % flutter doctor -v[✓] Flutter (Channel beta, 2.1.0-12.2.pre, on macOS 11.2.3 20D91 darwin-x64, locale en-IN)    • Flutter version 2.1.0-12.2.pre at /Users/abhishekkumar/flutter    • Framework revision 5bedb7b1d5 (13 days ago), 2021-03-17 17:06:30 -0700    • Engine revision 711ab3fda0    • Dart version 2.13.0 (build 2.13.0-116.0.dev)[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)    • Android SDK at /Users/abhishekkumar/Library/Android/sdk    • Platform android-30, build-tools 30.0.2    • ANDROID_HOME = /Users/abhishekkumar/Library/Android/sdk    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)    • All Android licenses accepted.[✓] Xcode - develop for iOS and macOS    • Xcode at /Applications/Xcode.app/Contents/Developer    • Xcode 12.4, Build version 12D4e    • CocoaPods version 1.10.1[✓] Chrome - develop for the web    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome[✓] Android Studio (version 4.1)    • Android Studio at /Applications/Android Studio.app/Contents    • Flutter plugin can be installed from:      🔨 https://plugins.jetbrains.com/plugin/9212-flutter    • Dart plugin can be installed from:      🔨 https://plugins.jetbrains.com/plugin/6351-dart    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)[✓] VS Code (version 1.51.1)    • VS Code at /Applications/Visual Studio Code.app/Contents    • Flutter extension version 3.17.0[✓] Connected device (3 available)    • iPhone SE (1st generation) (mobile) • 035FA189-09FF-46B5-96AC-C34E8D068C21 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)    • macOS (desktop)                     • macos                                • darwin-x64     • macOS 11.2.3 20D91 darwin-x64    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 89.0.4389.90• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: null-safetySupport for Dart's null safety featured: api docsIssues with https://api.flutter.dev/d: examplesSample code and demosf: routesNavigator, Router, and related APIs.found in release: 2.0Found to occur in 2.0frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp