1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

Move library to a top-level variable, since it never changes (#887)

This commit is contained in:
Kevin Moore
2021-08-26 16:18:40 -07:00
committed by GitHub
parent ecf716dcab
commit c9688ca34b
8 changed files with 77 additions and 114 deletions

View File

@@ -5,10 +5,8 @@
import 'package:flutter/material.dart';
import 'auth.dart';
import 'data.dart';
import 'routing.dart';
import 'screens/navigator.dart';
import 'widgets/library_scope.dart';
class Bookstore extends StatefulWidget {
const Bookstore({Key? key}) : super(key: key);
@@ -24,28 +22,6 @@ class _BookstoreState extends State<Bookstore> {
late final SimpleRouterDelegate _routerDelegate;
late final TemplateRouteParser _routeParser;
final library = Library()
..addBook(
title: 'Left Hand of Darkness',
authorName: 'Ursula K. Le Guin',
isPopular: true,
isNew: true)
..addBook(
title: 'Too Like the Lightning',
authorName: 'Ada Palmer',
isPopular: false,
isNew: true)
..addBook(
title: 'Kindred',
authorName: 'Octavia E. Butler',
isPopular: true,
isNew: false)
..addBook(
title: 'The Lathe of Heaven',
authorName: 'Ursula K. Le Guin',
isPopular: false,
isNew: false);
@override
void initState() {
/// Configure the parser with all of the app's allowed path templates.
@@ -85,12 +61,9 @@ class _BookstoreState extends State<Bookstore> {
notifier: _routeState,
child: BookstoreAuthScope(
notifier: _auth,
child: LibraryScope(
library: library,
child: MaterialApp.router(
routerDelegate: _routerDelegate,
routeInformationParser: _routeParser,
),
child: MaterialApp.router(
routerDelegate: _routerDelegate,
routeInformationParser: _routeParser,
),
),
);