Not working with VRouter
CodingSoot opened this issue · comments
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'),
),
);
}