The TabBar's selection is now represented by a TabBarSelection object which encapsulates both the previous and currently selected indices and the Performance used to animate the selection indicator. Added a TabBarView class which displays a tab's contents. It uses a shared TabBarSelection to stay in sync with a TabBar. The TabBarView scrolls in sync with the TabBar when the selection changes. Eventually it will allow one to fling the selection forward or backwards. Added a tabBar property to ToolBar. Typically the corresponding TabBarView will be the body of the toolbar's Scaffold. Removed TabNavigatorView and TabNavigator. Added a widget gallery tabs demo page. Removed the old tabs demo.
62 lines
1.6 KiB
Dart
62 lines
1.6 KiB
Dart
// Copyright 2015 The Chromium 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 'demo/widget_demo.dart';
|
|
|
|
class GalleryPage extends StatelessComponent {
|
|
GalleryPage({ this.demos, this.active, this.onThemeChanged });
|
|
|
|
final List<WidgetDemo> demos;
|
|
final WidgetDemo active;
|
|
final ValueChanged<ThemeData> onThemeChanged;
|
|
|
|
void _showDrawer(BuildContext context) {
|
|
List<Widget> items = <Widget>[
|
|
new DrawerHeader(child: new Text('Material demos')),
|
|
];
|
|
|
|
for (WidgetDemo demo in demos) {
|
|
items.add(new DrawerItem(
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(demo.routeName);
|
|
},
|
|
child: new Text(demo.title)
|
|
));
|
|
}
|
|
|
|
showDrawer(context: context, child: new Block(items));
|
|
}
|
|
|
|
Widget _body(BuildContext context) {
|
|
if (active != null)
|
|
return active.builder(context);
|
|
return new Material(
|
|
child: new Center(
|
|
child: new Text('Select a demo from the drawer')
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget _tabBar(BuildContext context) {
|
|
final WidgetBuilder builder = active?.tabBarBuilder;
|
|
return builder != null ? builder(context) : null;
|
|
}
|
|
|
|
Widget build(BuildContext context) {
|
|
return new Scaffold(
|
|
toolBar: new ToolBar(
|
|
left: new IconButton(
|
|
icon: 'navigation/menu',
|
|
onPressed: () { _showDrawer(context); }
|
|
),
|
|
center: new Text(active?.title ?? 'Material gallery'),
|
|
tabBar: _tabBar(context)
|
|
),
|
|
body: _body(context)
|
|
);
|
|
}
|
|
}
|