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

Not working with VRouter #3

Open
CodingSoot opened this issue Jan 28, 2022 · 0 comments
Open

Not working with VRouter #3

CodingSoot opened this issue Jan 28, 2022 · 0 comments

Comments

@CodingSoot
Copy link

When running the integration test in the example folder, I get this failure :

00:00 +0: VRouter
[VRouter: INFO] Successfully navigated to "/" using VRouter.to o
[VRouter: INFO] Successfully navigated to "/dashboard" using VRouter.to o
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
  Expected: exactly one matching node in the widget tree
  Actual: _WidgetTypeFinder:<zero widgets with type "DashboardMenu" (ignoring offstage widgets)>
   Which: means none were found but one was expected

As you can see, the Sidebar doesn't react to the route changes.

Here is a simplified example where you can verify that it's indeed not working : (Press on the FAB to go to a random path)

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:routed_widget_switcher/routed_widget_switcher.dart';
import 'package:vrouter/vrouter.dart';

void main() {
  runApp(VRouterApp());
}

class VRouterApp extends StatelessWidget {
  const VRouterApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return VRouter(
        builder: (_, navigator) {
          // Wrap the navigator in a simple scaffold, with a persistent `SideBar` on the left
          return Row(
            children: [
              const SideBar(),
              Expanded(child: navigator),
            ],
          );
        },
        routes: [
          VWidget.builder(
            path: '*',
            builder: (_, data) => MainScaffold(data.url ?? ''),
          ),
        ]);
  }
}

class SideBar extends StatelessWidget {
  const SideBar({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    Widget buildSideBarBg(Widget child) =>
        Material(child: SizedBox(width: 180, child: child));
    return buildSideBarBg(
      RoutedSwitcher(
        builders: (info) {
          // PROBLEM : Always prints '/'
          print(info.url);
          return [
            // Wildcard will match any route
            Routed('*', MainMenu.new),
            Routed('/dashboard', DashboardMenu.new),
            Routed('/settings', SettingsMenu.new),
          ];
        },
      ),
    );
  }
}

class MainScaffold extends StatelessWidget {
  final String location;

  static const paths = [
    '/',
    '/pageA',
    '/pageB',
    '/dashboard',
    '/dashboard/foo',
    '/dashboard/bar',
    '/settings',
    '/settings/foo',
    '/settings/bar',
  ];

  static final random = Random();

  const MainScaffold(this.location, {Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            final int i = random.nextInt(9);

            context.vRouter.to(paths[i]);
          },
        ),
        body: SafeArea(
          child: Center(child: Text(location)),
        ));
  }
}

/// Stub
class MainMenu extends StatelessWidget {
  MainMenu({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Container(
        color: Colors.red,
        child: const Center(
          child: Text('MAIN MENU'),
        ),
      );
}

/// Stub
class DashboardMenu extends StatelessWidget {
  DashboardMenu({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Container(
        color: Colors.blue,
        child: const Center(
          child: Text('DASHBOARD\nMENU'),
        ),
      );
}

/// Stub
class SettingsMenu extends StatelessWidget {
  SettingsMenu({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Container(
        color: Colors.green,
        child: const Center(
          child: Text('SETTINGS MENU'),
        ),
      );
}
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