lukepighetti / fluro

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
https://pub.dev/packages/fluro
MIT License
3.66k stars 416 forks source link

The argument type 'AuthWrapper Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type 'Widget? Function(BuildContext?, Map<String, List<String>>)'. #240

Open SeifAlmoatazBellah opened 2 years ago

SeifAlmoatazBellah commented 2 years ago

Hello i have an error with Fluro when i set handlerFunc this is my codes: ` class AppRouter { static final router = FluroRouter();

var usersHandler = Handler( handlerFunc: (BuildContext context, Map<String, dynamic> params) { return AuthWrapper(); }, );

void defineRoutes(FluroRouter router) { router.define("/auth", handler: usersHandler); } } AuthWrapper screen: class AuthWrapper extends StatefulWidget { const AuthWrapper({Key? key}) : super(key: key);

@override _AuthWrapperState createState() => _AuthWrapperState(); }

class _AuthWrapperState extends State { bool loading = false;

@override Widget build(BuildContext context) { ThemeSetting theme = Provider.of(context); return AnnotatedRegion( value: SystemUiOverlayStyle( statusBarIconBrightness: Brightness.light, statusBarColor: Colors.transparent, systemNavigationBarIconBrightness: Brightness.light, systemNavigationBarColor: Colors.transparent, ), child: loading ? Scaffold( backgroundColor: theme.primary, body: Center( child: LoadingWidget(), ), ) : Scaffold( backgroundColor: theme.primary, bottomNavigationBar: BottomAppBar( elevation: 0, color: Colors.transparent, child: TabBar( labelColor: theme.secondary, unselectedLabelColor: theme.secondary.withOpacity(.8), indicatorColor: theme.secondary, tabs: [ Tab(text: 'SignIn'), Tab(text: 'SignUp'), ], ), ), body: TabBarView( children: [ SignUp(), SignIn(), ], ), ), ); } } `

surpass404 commented 2 years ago

有解决吗

surpass404 commented 2 years ago

How to deal with it?

RemcoSchrijver commented 2 years ago

Instatiate your handler function like this: var usersHandler = Handler( handlerFunc: (BuildContext? context, Map<String, dynamic> params) { return AuthWrapper(); }, );

You need to allow BuildContext to be null to actually match the right parameter for the constructor of Handler. So use BuildContext? context

GenPingYuan commented 2 years ago

Instatiate your handler function like this: var usersHandler = Handler( handlerFunc: (BuildContext? context, Map<String, dynamic> params) { return AuthWrapper(); }, );

You need to allow BuildContext to be null to actually match the right parameter for the constructor of Handler. So use BuildContext? context

Thank you