Logo-amall

Issue: Widgetbook and GoRoute

Last active 4 days ago

8 replies

0 views

  • TO

    I found a issue about widgetbook and GoRoute below:
    So, because application depends on widgetbook 2.4.1, version solving failed.
    pub get failed (1; So, because application depends on widgetbook 2.4.1, version solving failed.)

    How to fix this?

  • KM

    I have the same problem. gorouter v5 has some breaking changes, so it doesn't seem possible to simply upgrade. Related gorouter issue
    GoRouter v5 migration guide

  • KM

    For now, I was able to solve it by dependency_override.
    Add following line to pubspec.yml

    myproject/pubspec.yml

    dependencyoverrides: widgetbook: path: ./widgetbookpatch/
    Copy widgetbook 24.1 to myproject/widgetbook_patch. and add following line.

    widgetbook_patch/pubspec.yml

    dependencies:
    go_router: ^5.0.0 // change version.

    widgetbook_patch/widgetbook.dart (line 363)

      child: MaterialApp.router(
        routeInformationProvider: goRouter.routeInformationProvider, // add this
        routeInformationParser: goRouter.routeInformationParser,
        routerDelegate: goRouter.routerDelegate,
        title: widget.appInfo.name,
        themeMode: ThemeMode.dark,
        debugShowCheckedModeBanner: false,
        darkTheme: Styles.darkTheme,
        theme: Styles.lightTheme,
      ),
    

    cf. GoRouter v4 breaking change

    widgetbookpatch/lib/src/rendering/builders/appbuilder.dart (line 25)

    Widget _defaultAppBuilderMethod(BuildContext context, Widget child) {
    final _router = getRouter(child);
    return WidgetsApp.router(
    color: Colors.transparent,
    builder: (context, childWidget) {
    return childWidget ?? child;
    },
    routeInformationProvider: _router.routeInformationProvider, // add this line
    routeInformationParser: _router.routeInformationParser,
    routerDelegate: _router.routerDelegate,
    );
    }

    widgetbook_patch/lib/src/navigation/router.dart

    GoRouter createRouter({
    required WorkbenchProvider workbenchProvider,
    required PreviewProvider previewProvider,
    }) {
    final router = GoRouter(
    redirect: (context, routerState) { // add 'context'
    final theme = routerState.queryParams['theme'];
    final locale = routerState.queryParams['locale'];
    final device = routerState.queryParams['device'];
    final textScaleFactor = routerState.queryParams['text-scale-factor'];
    final orientation = routerState.queryParams['orientation'];
    final frame = routerState.queryParams['frame'];
    final path = routerState.queryParams['path'];
    cf. GoRouter v5 migration guide
    Sorry, this worked in my project but I haven't tested it.
    I'm ready to cooperate to fix this issue although I'm begginer to Flutter. Is there anything I can do?

  • PA

    Please migrate to gorouter: 5.1.1 Because widgetbook 2.4.1 depends on gorouter ^3.0.5 and no versions of widgetbook match >2.4.1 <3.0.0, widgetbook ^2.4.1 requires go_router ^3.0.5.

  • SI

    Please migrate to go_router ^6.0.0.
    Because widgetbook &gt;=3.0.0-beta.1 depends on go_router ^5.2.1 and my_project depends on go_router ^6.0.0, widgetbook &gt;=3.0.0-beta.1 is forbidden

  • UN

    Ideally, I think navigation should be implemented in widgetbook itself without go_router, just like bloc package was replaced in the past (#28). Any plans to do so?

  • JE

    > Ideally, I think navigation should be implemented in widgetbook itself without go_router, just like bloc package was replaced in the past (#28). Any plans to do so?

    I totally and in the far future we are also aiming to do so. However, we think this will slow down development as it'll make the package harder to maintain. Therefore, we'll keep the dependency for now.

  • JE

    We just merged a PR that bumps go_router version to the most recent and fixes general navigation problems.

    We'll now add tests and release a new Widetbook version next week. Stay tuned!

Last active 4 days ago

8 replies

0 views