'How to convert widget to widget??
the handlerFunc wants to widget? but i have widget. And i have an error : The argument type 'SplashScreen Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type 'Widget? Function(BuildContext?, Map<String, List>)'.
class Flurouter {
static final FluroRouter router = FluroRouter();
static final Handler _splashHandler = Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) =>
SplashScreen());
static final Handler _mainHandler = Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) =>
LandingPage(
page: params['name'][0],
extra: '',
)); // this one is for one paramter passing...
// lets create for two parameters tooo...
static final Handler _mainHandler2 = Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) =>
LandingPage(
page: params['name'][0],
extra: params['extra'][0],
));
// ok its all set now .....
// now lets have a handler for passing parameter tooo....
static void setupRouter() {
router.define(
'/',
handler: _splashHandler,
);
router.define(
'/main/:name',
handler: _mainHandler,
transitionType: TransitionType.fadeIn,
);
router.define(
'/main/:name/:extra',
handler: _mainHandler2,
transitionType: TransitionType.fadeIn,
);
}
}
Solution 1:[1]
I realized that I can't convert the widget. But I can ensure null safety like this:
class Flurouter {
static final FluroRouter router = FluroRouter();
//Handlers setup here Where will I go?
//parameterless redirects
static final Handler _splashHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
return const SplashScreen();
});
// one parameter redirects if you add extra thing
static final Handler _mainHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
return LandingPage(
page: params['name'][0],
extra: '',
);
});
static void setupRouter() {
router.define('/', handler: _splashHandler);
router.define('/:name', handler: _mainHandler);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ba?ak Nisan ?vgen |
