From 5e63ef13260b88329efb9cf996d4893e0db51675 Mon Sep 17 00:00:00 2001 From: Seolin Date: Fri, 14 Jul 2023 00:57:44 +0900 Subject: [PATCH] Fix Router Config Issues #4300 (go_router_builder/example) (#4369) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR is an extension of the previous PR #4300 that I submitted. The previous PR, being based on the main branch, was closed and the contents were copied to a new branch in order to make further contributions.😅 In the previous PR, an assertion error was fixed by adding `routeInformationProvider` to `MaterialApp.router`. After a series of code reviews, we updated to use routerConfig and added some test codes. All the contents have been transferred to the current `bugfix/RouterConfig` branch. --- *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* --- .../example/lib/all_types.dart | 4 +--- .../go_router_builder/example/lib/main.dart | 4 +--- .../example/lib/simple_example.dart | 3 +-- .../example/test/simple_example_test.dart | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 packages/go_router_builder/example/test/simple_example_test.dart diff --git a/packages/go_router_builder/example/lib/all_types.dart b/packages/go_router_builder/example/lib/all_types.dart index ce86905afc0e..165523b1b3c0 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( diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 84b28c2ae562..773b6687ed93 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, ), diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index dee29d0c867c..dbb0a15a69c9 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -18,8 +18,7 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) => MaterialApp.router( - routeInformationParser: _router.routeInformationParser, - routerDelegate: _router.routerDelegate, + routerConfig: _router, title: _appTitle, ); 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 000000000000..80c51864740a --- /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); + } + }); +}