Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected a value of type 'Handler', but got one of type 'Null' #273

Open
ghost opened this issue Aug 18, 2022 · 1 comment
Open

Expected a value of type 'Handler', but got one of type 'Null' #273

ghost opened this issue Aug 18, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 18, 2022

I have url : www.foobar.com/template/1234&token=1234 where the first 1234 is the template id. here is my code:

class CustomRouter {
  static FluroRouter router = FluroRouter();
  static final Handler _splashPage = Handler(
    handlerFunc: ((context, parameters) {
      return const SplashPage();
    }),
  );
  static final Handler _templatePageHandler = Handler(
    handlerFunc: ((context, parameters) {
      String templateId = parameters['tID']!.first;
      return const TemplatePage(templateId: templateId);
    }),
  );
 
  static void defineRoutes() {
    router.define("/", handler: _splashPage);
    router.define(
      "/template/:templateId",
      handler: _templatePageHandler,
      transitionType: TransitionType.fadeIn,
    );
  }
}

and the app.dart is as:

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {
    super.initState();
    CustomRouter.defineRoutes();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Name",
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      onGenerateRoute: CustomRouter.router.generator,
    );
  }
}

Throws an Expected a value of type 'Handler', but got one of type 'Null'. When I tried running the same code but without the :templateId it works fine.

@jdechicchis
Copy link

I was hitting the same issue. Added the following as suggested here and it fixed it:

router.notFoundHandler = Handler(
        handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
      return NotFoundPage();
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant