1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-11 15:28:44 +00:00

navigation_and_routing: a bunch of cleanup (#886)

Fail early on nullable context objects - no code paths allow null
Eliminate superfluous private function
Use a function over an abstract class with one method
This commit is contained in:
Kevin Moore
2021-08-26 16:14:29 -07:00
committed by GitHub
parent ad6dc454f2
commit ecf716dcab
13 changed files with 84 additions and 122 deletions

View File

@@ -28,7 +28,7 @@ class AuthorDetailsScreen extends StatelessWidget {
child: BookList(
books: author.books,
onTap: (book) {
RouteStateScope.of(context)!.go('/book/${book.id}');
RouteStateScope.of(context).go('/book/${book.id}');
},
),
),

View File

@@ -21,7 +21,7 @@ class AuthorsScreen extends StatelessWidget {
body: AuthorList(
authors: LibraryScope.of(context).allAuthors,
onTap: (author) {
RouteStateScope.of(context)!.go('/author/${author.id}');
RouteStateScope.of(context).go('/author/${author.id}');
},
),
);

View File

@@ -93,7 +93,7 @@ class _BooksScreenState extends State<BooksScreen>
);
}
RouteState get _routeState => RouteStateScope.of(context)!;
RouteState get _routeState => RouteStateScope.of(context);
void _handleBookTapped(Book book) {
_routeState.go('/book/${book.id}');

View File

@@ -37,8 +37,8 @@ class _BookstoreNavigatorState extends State<BookstoreNavigator> {
@override
Widget build(BuildContext context) {
final routeState = RouteStateScope.of(context)!;
final authState = BookstoreAuthScope.of(context)!;
final routeState = RouteStateScope.of(context);
final authState = BookstoreAuthScope.of(context);
final pathTemplate = routeState.route.pathTemplate;
final library = LibraryScope.of(context);

View File

@@ -15,7 +15,7 @@ class BookstoreScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
final routeState = RouteStateScope.of(context)!;
final routeState = RouteStateScope.of(context);
final selectedIndex = _getSelectedIndex(routeState.route.pathTemplate);
return Scaffold(

View File

@@ -21,7 +21,7 @@ class BookstoreScaffoldBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
var currentRoute = RouteStateScope.of(context)!.route;
var currentRoute = RouteStateScope.of(context).route;
// A nested Router isn't necessary because the back button behavior doesn't
// need to be customized.

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';
import '../auth/auth.dart';
import '../auth.dart';
import '../routing.dart';
class SettingsScreen extends StatefulWidget {
@@ -52,7 +52,7 @@ class SettingsContent extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
BookstoreAuthScope.of(context)!.signOut();
BookstoreAuthScope.of(context).signOut();
},
child: const Text('Sign out'),
),
@@ -66,7 +66,7 @@ class SettingsContent extends StatelessWidget {
TextButton(
child: const Text('Go directly to /book/0 (RouteState)'),
onPressed: () {
RouteStateScope.of(context)!.go('/book/0');
RouteStateScope.of(context).go('/book/0');
},
),
].map((w) => Padding(padding: const EdgeInsets.all(8), child: w)),