From cc49e48d669a3eeb77b3e795cdad0bfc58796ac9 Mon Sep 17 00:00:00 2001 From: Seolin Date: Mon, 26 Jun 2023 17:06:25 +0900 Subject: [PATCH 1/5] Fix AssertionError by adding routeInformationProvider to MaterialApp.router --- packages/go_router_builder/example/lib/simple_example.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index dee29d0c867..e7e743dd541 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -18,6 +18,7 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) => MaterialApp.router( + routeInformationProvider: _router.routeInformationProvider, routeInformationParser: _router.routeInformationParser, routerDelegate: _router.routerDelegate, title: _appTitle, From 71de30c71d6fe96a01360c412c94ab33b07b8f47 Mon Sep 17 00:00:00 2001 From: Seolin Date: Tue, 27 Jun 2023 09:50:36 +0900 Subject: [PATCH 2/5] Fix. Support routerConfig --- .../go_router_builder/example/lib/main.dart | 20 +++++++------------ .../example/lib/simple_example.dart | 4 +--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 84b28c2ae56..0f3966be071 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -26,9 +26,7 @@ class App extends StatelessWidget { Widget build(BuildContext context) => ChangeNotifierProvider.value( value: loginInfo, child: MaterialApp.router( - routeInformationParser: _router.routeInformationParser, - routerDelegate: _router.routerDelegate, - routeInformationProvider: _router.routeInformationProvider, + routerConfig: _router, title: title, debugShowCheckedModeBanner: false, ), @@ -98,8 +96,7 @@ class LoginRoute extends GoRouteData { final String? fromPage; @override - Widget build(BuildContext context, GoRouterState state) => - LoginScreen(from: fromPage); + Widget build(BuildContext context, GoRouterState state) => LoginScreen(from: fromPage); } class FamilyRoute extends GoRouteData { @@ -256,11 +253,9 @@ class PersonScreen extends StatelessWidget { body: ListView( children: [ ListTile( - title: Text( - '${person.name} ${family.name} is ${person.age} years old'), + title: Text('${person.name} ${family.name} is ${person.age} years old'), ), - for (final MapEntry entry - in person.details.entries) + for (final MapEntry entry in person.details.entries) ListTile( title: Text( '${entry.key.name} - ${entry.value}', @@ -274,8 +269,8 @@ class PersonScreen extends StatelessWidget { ).go(context), child: const Text('With extra...'), ), - onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) - .go(context), + onTap: () => + PersonDetailsRoute(family.id, person.id, entry.key).go(context), ) ], ), @@ -308,8 +303,7 @@ class PersonDetailsPage extends StatelessWidget { ), ), if (extra == null) const ListTile(title: Text('No extra click!')), - if (extra != null) - ListTile(title: Text('Extra click count: $extra')), + if (extra != null) ListTile(title: Text('Extra click count: $extra')), ], ), ); diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index e7e743dd541..dbb0a15a69c 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -18,9 +18,7 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) => MaterialApp.router( - routeInformationProvider: _router.routeInformationProvider, - routeInformationParser: _router.routeInformationParser, - routerDelegate: _router.routerDelegate, + routerConfig: _router, title: _appTitle, ); From d2ae45c1fc6312864a58e4638380019a1c56e50e Mon Sep 17 00:00:00 2001 From: Seolin Date: Tue, 27 Jun 2023 10:40:08 +0900 Subject: [PATCH 3/5] Add. widget test for simple_example.dart --- .../example/test/simple_example_test.dart | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/go_router_builder/example/test/simple_example_test.dart diff --git a/packages/go_router_builder/example/test/simple_example_test.dart b/packages/go_router_builder/example/test/simple_example_test.dart new file mode 100644 index 00000000000..80c51864740 --- /dev/null +++ b/packages/go_router_builder/example/test/simple_example_test.dart @@ -0,0 +1,20 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:go_router_builder_example/shared/data.dart'; +import 'package:go_router_builder_example/simple_example.dart'; + +void main() { + testWidgets('App starts on HomeScreen and displays families', + (WidgetTester tester) async { + await tester.pumpWidget(App()); + expect(find.byType(HomeScreen), findsOneWidget); + expect(find.byType(ListTile), findsNWidgets(familyData.length)); + for (final Family family in familyData) { + expect(find.text(family.name), findsOneWidget); + } + }); +} From 158a6c5e037321585338a49f8dc9437c1524f541 Mon Sep 17 00:00:00 2001 From: Seolin Date: Wed, 28 Jun 2023 09:41:33 +0900 Subject: [PATCH 4/5] Reformat. `dart format .` --- packages/go_router_builder/example/lib/main.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 0f3966be071..773b6687ed9 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -96,7 +96,8 @@ class LoginRoute extends GoRouteData { final String? fromPage; @override - Widget build(BuildContext context, GoRouterState state) => LoginScreen(from: fromPage); + Widget build(BuildContext context, GoRouterState state) => + LoginScreen(from: fromPage); } class FamilyRoute extends GoRouteData { @@ -253,9 +254,11 @@ class PersonScreen extends StatelessWidget { body: ListView( children: [ ListTile( - title: Text('${person.name} ${family.name} is ${person.age} years old'), + title: Text( + '${person.name} ${family.name} is ${person.age} years old'), ), - for (final MapEntry entry in person.details.entries) + for (final MapEntry entry + in person.details.entries) ListTile( title: Text( '${entry.key.name} - ${entry.value}', @@ -269,8 +272,8 @@ class PersonScreen extends StatelessWidget { ).go(context), child: const Text('With extra...'), ), - onTap: () => - PersonDetailsRoute(family.id, person.id, entry.key).go(context), + onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) + .go(context), ) ], ), @@ -303,7 +306,8 @@ class PersonDetailsPage extends StatelessWidget { ), ), if (extra == null) const ListTile(title: Text('No extra click!')), - if (extra != null) ListTile(title: Text('Extra click count: $extra')), + if (extra != null) + ListTile(title: Text('Extra click count: $extra')), ], ), ); From 763e4bdae68e4c06d8668ae187ed948a11eb9737 Mon Sep 17 00:00:00 2001 From: Seolin Date: Wed, 28 Jun 2023 09:55:46 +0900 Subject: [PATCH 5/5] Fix. Support routerConfig --- packages/go_router_builder/example/lib/all_types.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/go_router_builder/example/lib/all_types.dart b/packages/go_router_builder/example/lib/all_types.dart index ce86905afc0..165523b1b3c 100644 --- a/packages/go_router_builder/example/lib/all_types.dart +++ b/packages/go_router_builder/example/lib/all_types.dart @@ -550,9 +550,7 @@ class AllTypesApp extends StatelessWidget { @override Widget build(BuildContext context) => MaterialApp.router( - routeInformationParser: _router.routeInformationParser, - routerDelegate: _router.routerDelegate, - routeInformationProvider: _router.routeInformationProvider, + routerConfig: _router, ); late final GoRouter _router = GoRouter(