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(),
);
CodePudding user response:
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
CodePudding user response:
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!)