Shahad
Shahad

Reputation: 31

flutter router : The argument type 'String?' can't be assigned to the parameter type 'String'

in my router.dart it is showing me this error: The argument type 'String?' can't be assigned to the parameter type 'String'

for the (settings.name)

Route<dynamic> generateRoute(RouteSettings settings) {
  switch (settings.name) {
    case LoginViewRoute:
      return _getPageRoute(
        routeName: settings.name,
        viewToShow: LoginView(),
      );
    case SignUpViewRoute:
      return _getPageRoute(
        routeName: settings.name,
        viewToShow: SignUpView(),
      );
    case HomeViewRoute:
      return _getPageRoute(
        routeName: settings.name,
        viewToShow: HomeView(),
      );

Upvotes: 0

Views: 877

Answers (3)

Manishyadav
Manishyadav

Reputation: 1736

Check some points with null safety declaration of data member of class. And also check out the type of action parameter what it takes- It may take String type of data then update your variables/data member accordingly.

Please look into the concept of null safety.

Upvotes: 0

Emirhan &#214;zgeliş
Emirhan &#214;zgeliş

Reputation: 82

Move the cursor over RouteSetting and press f12. Convert the name field from String to String? in the file you went to. Or at the end of the setting.name in the switch ! add sign. like (setting.name!)

Upvotes: 1

Yashraj
Yashraj

Reputation: 999

Replace settings.name with settings.name! or change String routeName to String? routeName in _getPageRoute.

For more info : https://dart.dev/null-safety/understanding-null-safety

Upvotes: 1

Related Questions