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

@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import '../data.dart';
import '../routing.dart';
import '../widgets/book_list.dart';
import '../widgets/library_scope.dart';
class BooksScreen extends StatefulWidget {
const BooksScreen({
@@ -50,48 +49,45 @@ class _BooksScreenState extends State<BooksScreen>
}
@override
Widget build(BuildContext context) {
final library = LibraryScope.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Books'),
bottom: TabBar(
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Books'),
bottom: TabBar(
controller: _tabController,
tabs: const [
Tab(
text: 'Popular',
icon: Icon(Icons.people),
),
Tab(
text: 'New',
icon: Icon(Icons.new_releases),
),
Tab(
text: 'All',
icon: Icon(Icons.list),
),
],
),
),
body: TabBarView(
controller: _tabController,
tabs: const [
Tab(
text: 'Popular',
icon: Icon(Icons.people),
children: [
BookList(
books: libraryInstance.popularBooks,
onTap: _handleBookTapped,
),
Tab(
text: 'New',
icon: Icon(Icons.new_releases),
BookList(
books: libraryInstance.newBooks,
onTap: _handleBookTapped,
),
Tab(
text: 'All',
icon: Icon(Icons.list),
BookList(
books: libraryInstance.allBooks,
onTap: _handleBookTapped,
),
],
),
),
body: TabBarView(
controller: _tabController,
children: [
BookList(
books: library.popularBooks,
onTap: _handleBookTapped,
),
BookList(
books: library.newBooks,
onTap: _handleBookTapped,
),
BookList(
books: library.allBooks,
onTap: _handleBookTapped,
),
],
),
);
}
);
RouteState get _routeState => RouteStateScope.of(context);