Commit 248960a7 authored by Adam Barth's avatar Adam Barth

Add a route table to Material Gallery (#3457)

Use the route table to generate the list of screens to test in the smoke test.
parent 986b0174
...@@ -45,6 +45,8 @@ const String _actionText = ...@@ -45,6 +45,8 @@ const String _actionText =
const String _actionCode = 'buttons_action'; const String _actionCode = 'buttons_action';
class ButtonsDemo extends StatefulWidget { class ButtonsDemo extends StatefulWidget {
static const String routeName = '/buttons';
@override @override
_ButtonsDemoState createState() => new _ButtonsDemoState(); _ButtonsDemoState createState() => new _ButtonsDemoState();
} }
......
...@@ -118,6 +118,8 @@ class TravelDestinationItem extends StatelessWidget { ...@@ -118,6 +118,8 @@ class TravelDestinationItem extends StatelessWidget {
} }
class CardsDemo extends StatelessWidget { class CardsDemo extends StatelessWidget {
static const String routeName = '/cards';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ChipDemo extends StatefulWidget { class ChipDemo extends StatefulWidget {
static const String routeName = '/chip';
@override @override
_ChipDemoState createState() => new _ChipDemoState(); _ChipDemoState createState() => new _ChipDemoState();
} }
......
...@@ -109,6 +109,8 @@ class ColorSwatchTabView extends StatelessWidget { ...@@ -109,6 +109,8 @@ class ColorSwatchTabView extends StatelessWidget {
} }
class ColorsDemo extends StatelessWidget { class ColorsDemo extends StatelessWidget {
static const String routeName = '/colors';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new TabBarSelection<ColorSwatch>( return new TabBarSelection<ColorSwatch>(
......
...@@ -20,6 +20,8 @@ class Desert { ...@@ -20,6 +20,8 @@ class Desert {
} }
class DataTableDemo extends StatefulWidget { class DataTableDemo extends StatefulWidget {
static const String routeName = '/data-table';
@override @override
_DataTableDemoState createState() => new _DataTableDemoState(); _DataTableDemoState createState() => new _DataTableDemoState();
} }
......
...@@ -8,6 +8,8 @@ import 'package:flutter/material.dart'; ...@@ -8,6 +8,8 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
class DatePickerDemo extends StatefulWidget { class DatePickerDemo extends StatefulWidget {
static const String routeName = '/date-picker';
@override @override
_DatePickerDemoState createState() => new _DatePickerDemoState(); _DatePickerDemoState createState() => new _DatePickerDemoState();
} }
......
...@@ -55,6 +55,8 @@ class DialogDemoItem extends StatelessWidget { ...@@ -55,6 +55,8 @@ class DialogDemoItem extends StatelessWidget {
} }
class DialogDemo extends StatefulWidget { class DialogDemo extends StatefulWidget {
static const String routeName = '/dialog';
@override @override
DialogDemoState createState() => new DialogDemoState(); DialogDemoState createState() => new DialogDemoState();
} }
......
...@@ -10,6 +10,8 @@ import 'package:flutter/services.dart'; ...@@ -10,6 +10,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_sprites/flutter_sprites.dart'; import 'package:flutter_sprites/flutter_sprites.dart';
class DrawingDemo extends StatefulWidget { class DrawingDemo extends StatefulWidget {
static const String routeName = '/drawing';
@override @override
_DrawingDemoState createState() => new _DrawingDemoState(); _DrawingDemoState createState() => new _DrawingDemoState();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class DropDownDemo extends StatefulWidget { class DropDownDemo extends StatefulWidget {
static const String routeName = '/dropdown';
@override @override
_DropDownDemoState createState() => new _DropDownDemoState(); _DropDownDemoState createState() => new _DropDownDemoState();
} }
......
...@@ -16,6 +16,8 @@ SpriteSheet _sprites; ...@@ -16,6 +16,8 @@ SpriteSheet _sprites;
class FitnessDemo extends StatelessWidget { class FitnessDemo extends StatelessWidget {
FitnessDemo({ Key key }) : super(key: key); FitnessDemo({ Key key }) : super(key: key);
static const String routeName = '/fitness';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
......
...@@ -70,6 +70,8 @@ class _ContactItem extends StatelessWidget { ...@@ -70,6 +70,8 @@ class _ContactItem extends StatelessWidget {
} }
class FlexibleSpaceDemo extends StatefulWidget { class FlexibleSpaceDemo extends StatefulWidget {
static const String routeName = '/flexible-space';
@override @override
FlexibleSpaceDemoState createState() => new FlexibleSpaceDemoState(); FlexibleSpaceDemoState createState() => new FlexibleSpaceDemoState();
} }
......
...@@ -132,6 +132,8 @@ class GridDemoPhotoItem extends StatelessWidget { ...@@ -132,6 +132,8 @@ class GridDemoPhotoItem extends StatelessWidget {
class GridListDemo extends StatefulWidget { class GridListDemo extends StatefulWidget {
GridListDemo({ Key key }) : super(key: key); GridListDemo({ Key key }) : super(key: key);
static const String routeName = '/grid-list';
@override @override
GridListDemoState createState() => new GridListDemoState(); GridListDemoState createState() => new GridListDemoState();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class IconsDemo extends StatefulWidget { class IconsDemo extends StatefulWidget {
static const String routeName = '/icons';
@override @override
IconsDemoState createState() => new IconsDemoState(); IconsDemoState createState() => new IconsDemoState();
} }
......
...@@ -31,6 +31,8 @@ class LeaveBehindItem implements Comparable<LeaveBehindItem> { ...@@ -31,6 +31,8 @@ class LeaveBehindItem implements Comparable<LeaveBehindItem> {
class LeaveBehindDemo extends StatefulWidget { class LeaveBehindDemo extends StatefulWidget {
LeaveBehindDemo({ Key key }) : super(key: key); LeaveBehindDemo({ Key key }) : super(key: key);
static const String routeName = '/leave-behind';
@override @override
LeaveBehindDemoState createState() => new LeaveBehindDemoState(); LeaveBehindDemoState createState() => new LeaveBehindDemoState();
} }
......
...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; ...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart';
class ListDemo extends StatefulWidget { class ListDemo extends StatefulWidget {
ListDemo({ Key key }) : super(key: key); ListDemo({ Key key }) : super(key: key);
static const String routeName = '/list';
@override @override
ListDemoState createState() => new ListDemoState(); ListDemoState createState() => new ListDemoState();
} }
......
...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; ...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart';
class MenuDemo extends StatefulWidget { class MenuDemo extends StatefulWidget {
MenuDemo({ Key key }) : super(key: key); MenuDemo({ Key key }) : super(key: key);
static const String routeName = '/menu';
@override @override
MenuDemoState createState() => new MenuDemoState(); MenuDemoState createState() => new MenuDemoState();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ModalBottomSheetDemo extends StatelessWidget { class ModalBottomSheetDemo extends StatelessWidget {
static const String routeName = '/modal-bottom-sheet';
final TextStyle textStyle = new TextStyle( final TextStyle textStyle = new TextStyle(
color: Colors.indigo[400], color: Colors.indigo[400],
fontSize: 24.0, fontSize: 24.0,
......
...@@ -11,6 +11,8 @@ enum IndicatorType { overscroll, refresh } ...@@ -11,6 +11,8 @@ enum IndicatorType { overscroll, refresh }
class OverscrollDemo extends StatefulWidget { class OverscrollDemo extends StatefulWidget {
OverscrollDemo({ Key key }) : super(key: key); OverscrollDemo({ Key key }) : super(key: key);
static const String routeName = '/overscroll';
@override @override
OverscrollDemoState createState() => new OverscrollDemoState(); OverscrollDemoState createState() => new OverscrollDemoState();
} }
......
...@@ -6,6 +6,8 @@ import 'package:flutter/material.dart'; ...@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
class PageSelectorDemo extends StatelessWidget { class PageSelectorDemo extends StatelessWidget {
static const String routeName = '/page-selector';
void _handleArrowButtonPress(BuildContext context, int delta) { void _handleArrowButtonPress(BuildContext context, int delta) {
final TabBarSelectionState<IconData> selection = TabBarSelection.of/*<IconData>*/(context); final TabBarSelectionState<IconData> selection = TabBarSelection.of/*<IconData>*/(context);
if (!selection.valueIsChanging) if (!selection.valueIsChanging)
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class PersistentBottomSheetDemo extends StatefulWidget { class PersistentBottomSheetDemo extends StatefulWidget {
static const String routeName = '/persistent-bottom-sheet';
@override @override
_PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState(); _PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ProgressIndicatorDemo extends StatefulWidget { class ProgressIndicatorDemo extends StatefulWidget {
static const String routeName = '/progress-indicator';
@override @override
_ProgressIndicatorDemoState createState() => new _ProgressIndicatorDemoState(); _ProgressIndicatorDemoState createState() => new _ProgressIndicatorDemoState();
} }
......
...@@ -11,6 +11,8 @@ enum TabsDemoStyle { ...@@ -11,6 +11,8 @@ enum TabsDemoStyle {
} }
class ScrollableTabsDemo extends StatefulWidget { class ScrollableTabsDemo extends StatefulWidget {
static const String routeName = '/scrollable-tabs';
@override @override
ScrollableTabsDemoState createState() => new ScrollableTabsDemoState(); ScrollableTabsDemoState createState() => new ScrollableTabsDemoState();
} }
......
...@@ -29,6 +29,8 @@ const String _switchText = ...@@ -29,6 +29,8 @@ const String _switchText =
const String _switchCode = 'selectioncontrols_switch'; const String _switchCode = 'selectioncontrols_switch';
class SelectionControlsDemo extends StatefulWidget { class SelectionControlsDemo extends StatefulWidget {
static const String routeName = '/selection-controls';
@override @override
_SelectionControlsDemoState createState() => new _SelectionControlsDemoState(); _SelectionControlsDemoState createState() => new _SelectionControlsDemoState();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class SliderDemo extends StatefulWidget { class SliderDemo extends StatefulWidget {
static const String routeName = '/slider';
@override @override
_SliderDemoState createState() => new _SliderDemoState(); _SliderDemoState createState() => new _SliderDemoState();
} }
......
...@@ -20,6 +20,8 @@ const String _text3 = ...@@ -20,6 +20,8 @@ const String _text3 =
class SnackBarDemo extends StatefulWidget { class SnackBarDemo extends StatefulWidget {
SnackBarDemo({ Key key }) : super(key: key); SnackBarDemo({ Key key }) : super(key: key);
static const String routeName = '/snack-bar';
@override @override
_SnackBarDemoState createState() => new _SnackBarDemoState(); _SnackBarDemoState createState() => new _SnackBarDemoState();
} }
......
...@@ -19,6 +19,8 @@ final List<_Page> _pages = <_Page>[ ...@@ -19,6 +19,8 @@ final List<_Page> _pages = <_Page>[
]; ];
class TabsDemo extends StatefulWidget { class TabsDemo extends StatefulWidget {
static const String routeName = '/tabs';
@override @override
TabsDemoState createState() => new TabsDemoState(); TabsDemoState createState() => new TabsDemoState();
} }
......
...@@ -26,6 +26,8 @@ const String _explanatoryText = ...@@ -26,6 +26,8 @@ const String _explanatoryText =
"by its key."; "by its key.";
class TabsFabDemo extends StatefulWidget { class TabsFabDemo extends StatefulWidget {
static const String routeName = '/tabs-fab';
@override @override
_TabsFabDemoState createState() => new _TabsFabDemoState(); _TabsFabDemoState createState() => new _TabsFabDemoState();
} }
......
...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; ...@@ -7,6 +7,8 @@ import 'package:flutter/material.dart';
class TextFieldDemo extends StatefulWidget { class TextFieldDemo extends StatefulWidget {
TextFieldDemo({ Key key }) : super(key: key); TextFieldDemo({ Key key }) : super(key: key);
static const String routeName = '/text-field';
@override @override
TextFieldDemoState createState() => new TextFieldDemoState(); TextFieldDemoState createState() => new TextFieldDemoState();
} }
......
...@@ -7,6 +7,8 @@ import 'dart:async'; ...@@ -7,6 +7,8 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TimePickerDemo extends StatefulWidget { class TimePickerDemo extends StatefulWidget {
static const String routeName = '/time-picker';
@override @override
_TimePickerDemoState createState() => new _TimePickerDemoState(); _TimePickerDemoState createState() => new _TimePickerDemoState();
} }
......
...@@ -10,6 +10,9 @@ const String _introText = ...@@ -10,6 +10,9 @@ const String _introText =
"apps accessible, like screen readers."; "apps accessible, like screen readers.";
class TooltipDemo extends StatelessWidget { class TooltipDemo extends StatelessWidget {
static const String routeName = '/tooltip';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TwoLevelListDemo extends StatelessWidget { class TwoLevelListDemo extends StatelessWidget {
static const String routeName = '/two-level-list';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
......
...@@ -39,6 +39,8 @@ class TextStyleItem extends StatelessWidget { ...@@ -39,6 +39,8 @@ class TextStyleItem extends StatelessWidget {
} }
class TypographyDemo extends StatelessWidget { class TypographyDemo extends StatelessWidget {
static const String routeName = '/typography';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final TextTheme textTheme = Theme.of(context).textTheme; final TextTheme textTheme = Theme.of(context).textTheme;
......
...@@ -20,6 +20,8 @@ enum WeatherType { ...@@ -20,6 +20,8 @@ enum WeatherType {
class WeatherDemo extends StatefulWidget { class WeatherDemo extends StatefulWidget {
WeatherDemo({ Key key }) : super(key: key); WeatherDemo({ Key key }) : super(key: key);
static const String routeName = '/weather';
@override @override
_WeatherDemoState createState() => new _WeatherDemoState(); _WeatherDemoState createState() => new _WeatherDemoState();
} }
......
// Copyright 2016 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.
export 'demo/buttons_demo.dart';
export 'demo/cards_demo.dart';
export 'demo/colors_demo.dart';
export 'demo/chip_demo.dart';
export 'demo/data_table_demo.dart';
export 'demo/date_picker_demo.dart';
export 'demo/dialog_demo.dart';
export 'demo/drop_down_demo.dart';
export 'demo/drawing_demo.dart';
export 'demo/fitness_demo.dart';
export 'demo/flexible_space_demo.dart';
export 'demo/grid_list_demo.dart';
export 'demo/icons_demo.dart';
export 'demo/leave_behind_demo.dart';
export 'demo/list_demo.dart';
export 'demo/modal_bottom_sheet_demo.dart';
export 'demo/menu_demo.dart';
export 'demo/overscroll_demo.dart';
export 'demo/page_selector_demo.dart';
export 'demo/persistent_bottom_sheet_demo.dart';
export 'demo/progress_indicator_demo.dart';
export 'demo/selection_controls_demo.dart';
export 'demo/slider_demo.dart';
export 'demo/snack_bar_demo.dart';
export 'demo/scrollable_tabs_demo.dart';
export 'demo/tabs_demo.dart';
export 'demo/tabs_fab_demo.dart';
export 'demo/text_field_demo.dart';
export 'demo/time_picker_demo.dart';
export 'demo/tooltip_demo.dart';
export 'demo/two_level_list_demo.dart';
export 'demo/typography_demo.dart';
export 'demo/weather_demo.dart';
...@@ -5,8 +5,45 @@ ...@@ -5,8 +5,45 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation; import 'package:flutter/scheduler.dart' show timeDilation;
import '../demos.dart';
import 'home.dart'; import 'home.dart';
final Map<String, WidgetBuilder> kRoutes = <String, WidgetBuilder>{
WeatherDemo.routeName: (BuildContext context) => new WeatherDemo(),
FitnessDemo.routeName: (BuildContext context) => new FitnessDemo(),
DrawingDemo.routeName: (BuildContext context) => new DrawingDemo(),
FlexibleSpaceDemo.routeName: (BuildContext context) => new FlexibleSpaceDemo(),
TabsFabDemo.routeName: (BuildContext context) => new TabsFabDemo(),
ButtonsDemo.routeName: (BuildContext context) => new ButtonsDemo(),
CardsDemo.routeName: (BuildContext context) => new CardsDemo(),
ChipDemo.routeName: (BuildContext context) => new ChipDemo(),
DatePickerDemo.routeName: (BuildContext context) => new DatePickerDemo(),
DataTableDemo.routeName: (BuildContext context) => new DataTableDemo(),
DialogDemo.routeName: (BuildContext context) => new DialogDemo(),
DropDownDemo.routeName: (BuildContext context) => new DropDownDemo(),
TwoLevelListDemo.routeName: (BuildContext context) => new TwoLevelListDemo(),
GridListDemo.routeName: (BuildContext context) => new GridListDemo(),
IconsDemo.routeName: (BuildContext context) => new IconsDemo(),
LeaveBehindDemo.routeName: (BuildContext context) => new LeaveBehindDemo(),
ListDemo.routeName: (BuildContext context) => new ListDemo(),
MenuDemo.routeName: (BuildContext context) => new MenuDemo(),
ModalBottomSheetDemo.routeName: (BuildContext context) => new ModalBottomSheetDemo(),
OverscrollDemo.routeName: (BuildContext context) => new OverscrollDemo(),
PageSelectorDemo.routeName: (BuildContext context) => new PageSelectorDemo(),
PersistentBottomSheetDemo.routeName: (BuildContext context) => new PersistentBottomSheetDemo(),
ProgressIndicatorDemo.routeName: (BuildContext context) => new ProgressIndicatorDemo(),
ScrollableTabsDemo.routeName: (BuildContext context) => new ScrollableTabsDemo(),
SelectionControlsDemo.routeName: (BuildContext context) => new SelectionControlsDemo(),
SliderDemo.routeName: (BuildContext context) => new SliderDemo(),
SnackBarDemo.routeName: (BuildContext context) => new SnackBarDemo(),
TabsDemo.routeName: (BuildContext context) => new TabsDemo(),
TextFieldDemo.routeName: (BuildContext context) => new TextFieldDemo(),
TimePickerDemo.routeName: (BuildContext context) => new TimePickerDemo(),
TooltipDemo.routeName: (BuildContext context) => new TooltipDemo(),
ColorsDemo.routeName: (BuildContext context) => new ColorsDemo(),
TypographyDemo.routeName: (BuildContext context) => new TypographyDemo(),
};
class GalleryApp extends StatefulWidget { class GalleryApp extends StatefulWidget {
GalleryApp({ Key key }) : super(key: key); GalleryApp({ Key key }) : super(key: key);
...@@ -24,6 +61,7 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -24,6 +61,7 @@ class GalleryAppState extends State<GalleryApp> {
title: 'Flutter Material Gallery', title: 'Flutter Material Gallery',
theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme, theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme,
showPerformanceOverlay: _showPerformanceOverlay, showPerformanceOverlay: _showPerformanceOverlay,
routes: kRoutes,
home: new GalleryHome( home: new GalleryHome(
useLightTheme: _useLightTheme, useLightTheme: _useLightTheme,
onThemeChanged: (bool value) { setState(() { _useLightTheme = value; }); }, onThemeChanged: (bool value) { setState(() { _useLightTheme = value; }); },
......
// Copyright 2016 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 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
......
...@@ -5,44 +5,11 @@ ...@@ -5,44 +5,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import '../demos.dart';
import 'drawer.dart'; import 'drawer.dart';
import 'header.dart'; import 'header.dart';
import 'item.dart'; import 'item.dart';
import '../demo/buttons_demo.dart';
import '../demo/cards_demo.dart';
import '../demo/colors_demo.dart';
import '../demo/chip_demo.dart';
import '../demo/data_table_demo.dart';
import '../demo/date_picker_demo.dart';
import '../demo/dialog_demo.dart';
import '../demo/drop_down_demo.dart';
import '../demo/drawing_demo.dart';
import '../demo/fitness_demo.dart';
import '../demo/flexible_space_demo.dart';
import '../demo/grid_list_demo.dart';
import '../demo/icons_demo.dart';
import '../demo/leave_behind_demo.dart';
import '../demo/list_demo.dart';
import '../demo/modal_bottom_sheet_demo.dart';
import '../demo/menu_demo.dart';
import '../demo/overscroll_demo.dart';
import '../demo/page_selector_demo.dart';
import '../demo/persistent_bottom_sheet_demo.dart';
import '../demo/progress_indicator_demo.dart';
import '../demo/selection_controls_demo.dart';
import '../demo/slider_demo.dart';
import '../demo/snack_bar_demo.dart';
import '../demo/scrollable_tabs_demo.dart';
import '../demo/tabs_demo.dart';
import '../demo/tabs_fab_demo.dart';
import '../demo/text_field_demo.dart';
import '../demo/time_picker_demo.dart';
import '../demo/tooltip_demo.dart';
import '../demo/two_level_list_demo.dart';
import '../demo/typography_demo.dart';
import '../demo/weather_demo.dart';
const double _kFlexibleSpaceMaxHeight = 256.0; const double _kFlexibleSpaceMaxHeight = 256.0;
class GalleryHome extends StatefulWidget { class GalleryHome extends StatefulWidget {
...@@ -106,51 +73,51 @@ class GalleryHomeState extends State<GalleryHome> { ...@@ -106,51 +73,51 @@ class GalleryHomeState extends State<GalleryHome> {
leading: new Icon(icon: Icons.star), leading: new Icon(icon: Icons.star),
title: new Text('Demos'), title: new Text('Demos'),
children: <Widget>[ children: <Widget>[
new GalleryItem(title: 'Weather', builder: () => new WeatherDemo()), new GalleryItem(title: 'Weather', routeName: WeatherDemo.routeName),
new GalleryItem(title: 'Fitness', builder: () => new FitnessDemo()), new GalleryItem(title: 'Fitness', routeName: FitnessDemo.routeName),
new GalleryItem(title: 'Fancy lines', builder: () => new DrawingDemo()), new GalleryItem(title: 'Fancy lines', routeName: DrawingDemo.routeName),
new GalleryItem(title: 'Flexible space toolbar', builder: () => new FlexibleSpaceDemo()), new GalleryItem(title: 'Flexible space toolbar', routeName: FlexibleSpaceDemo.routeName),
new GalleryItem(title: 'Floating action button', builder: () => new TabsFabDemo()), new GalleryItem(title: 'Floating action button', routeName: TabsFabDemo.routeName),
] ]
), ),
new TwoLevelSublist( new TwoLevelSublist(
leading: new Icon(icon: Icons.extension), leading: new Icon(icon: Icons.extension),
title: new Text('Components'), title: new Text('Components'),
children: <Widget>[ children: <Widget>[
new GalleryItem(title: 'Buttons', builder: () => new ButtonsDemo()), new GalleryItem(title: 'Buttons', routeName: ButtonsDemo.routeName),
new GalleryItem(title: 'Cards', builder: () => new CardsDemo()), new GalleryItem(title: 'Cards', routeName: CardsDemo.routeName),
new GalleryItem(title: 'Chips', builder: () => new ChipDemo()), new GalleryItem(title: 'Chips', routeName: ChipDemo.routeName),
new GalleryItem(title: 'Date picker', builder: () => new DatePickerDemo()), new GalleryItem(title: 'Date picker', routeName: DatePickerDemo.routeName),
new GalleryItem(title: 'Data tables', builder: () => new DataTableDemo()), new GalleryItem(title: 'Data tables', routeName: DataTableDemo.routeName),
new GalleryItem(title: 'Dialog', builder: () => new DialogDemo()), new GalleryItem(title: 'Dialog', routeName: DialogDemo.routeName),
new GalleryItem(title: 'Drop-down button', builder: () => new DropDownDemo()), new GalleryItem(title: 'Drop-down button', routeName: DropDownDemo.routeName),
new GalleryItem(title: 'Expand/collapse list control', builder: () => new TwoLevelListDemo()), new GalleryItem(title: 'Expand/collapse list control', routeName: TwoLevelListDemo.routeName),
new GalleryItem(title: 'Grid', builder: () => new GridListDemo()), new GalleryItem(title: 'Grid', routeName: GridListDemo.routeName),
new GalleryItem(title: 'Icons', builder: () => new IconsDemo()), new GalleryItem(title: 'Icons', routeName: IconsDemo.routeName),
new GalleryItem(title: 'Leave-behind list items', builder: () => new LeaveBehindDemo()), new GalleryItem(title: 'Leave-behind list items', routeName: LeaveBehindDemo.routeName),
new GalleryItem(title: 'List', builder: () => new ListDemo()), new GalleryItem(title: 'List', routeName: ListDemo.routeName),
new GalleryItem(title: 'Menus', builder: () => new MenuDemo()), new GalleryItem(title: 'Menus', routeName: MenuDemo.routeName),
new GalleryItem(title: 'Modal bottom sheet', builder: () => new ModalBottomSheetDemo()), new GalleryItem(title: 'Modal bottom sheet', routeName: ModalBottomSheetDemo.routeName),
new GalleryItem(title: 'Over-scroll', builder: () => new OverscrollDemo()), new GalleryItem(title: 'Over-scroll', routeName: OverscrollDemo.routeName),
new GalleryItem(title: 'Page selector', builder: () => new PageSelectorDemo()), new GalleryItem(title: 'Page selector', routeName: PageSelectorDemo.routeName),
new GalleryItem(title: 'Persistent bottom sheet', builder: () => new PersistentBottomSheetDemo()), new GalleryItem(title: 'Persistent bottom sheet', routeName: PersistentBottomSheetDemo.routeName),
new GalleryItem(title: 'Progress indicators', builder: () => new ProgressIndicatorDemo()), new GalleryItem(title: 'Progress indicators', routeName: ProgressIndicatorDemo.routeName),
new GalleryItem(title: 'Scrollable tabs', builder: () => new ScrollableTabsDemo()), new GalleryItem(title: 'Scrollable tabs', routeName: ScrollableTabsDemo.routeName),
new GalleryItem(title: 'Selection controls', builder: () => new SelectionControlsDemo()), new GalleryItem(title: 'Selection controls', routeName: SelectionControlsDemo.routeName),
new GalleryItem(title: 'Sliders', builder: () => new SliderDemo()), new GalleryItem(title: 'Sliders', routeName: SliderDemo.routeName),
new GalleryItem(title: 'Snackbar', builder: () => new SnackBarDemo()), new GalleryItem(title: 'Snackbar', routeName: SnackBarDemo.routeName),
new GalleryItem(title: 'Tabs', builder: () => new TabsDemo()), new GalleryItem(title: 'Tabs', routeName: TabsDemo.routeName),
new GalleryItem(title: 'Text fields', builder: () => new TextFieldDemo()), new GalleryItem(title: 'Text fields', routeName: TextFieldDemo.routeName),
new GalleryItem(title: 'Time picker', builder: () => new TimePickerDemo()), new GalleryItem(title: 'Time picker', routeName: TimePickerDemo.routeName),
new GalleryItem(title: 'Tooltips', builder: () => new TooltipDemo()), new GalleryItem(title: 'Tooltips', routeName: TooltipDemo.routeName),
] ]
), ),
new TwoLevelSublist( new TwoLevelSublist(
leading: new Icon(icon: Icons.color_lens), leading: new Icon(icon: Icons.color_lens),
title: new Text('Style'), title: new Text('Style'),
children: <Widget>[ children: <Widget>[
new GalleryItem(title: 'Colors', builder: () => new ColorsDemo()), new GalleryItem(title: 'Colors', routeName: ColorsDemo.routeName),
new GalleryItem(title: 'Typography', builder: () => new TypographyDemo()), new GalleryItem(title: 'Typography', routeName: TypographyDemo.routeName),
] ]
) )
] ]
......
// Copyright 2016 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 'package:flutter/material.dart';
typedef Widget GalleryDemoBuilder(); typedef Widget GalleryDemoBuilder();
class GalleryItem extends StatelessWidget { class GalleryItem extends StatelessWidget {
GalleryItem({ this.title, this.icon, this.builder }); GalleryItem({ this.title, this.icon, this.routeName });
final String title; final String title;
final IconData icon; final IconData icon;
final GalleryDemoBuilder builder; final String routeName;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -17,11 +21,8 @@ class GalleryItem extends StatelessWidget { ...@@ -17,11 +21,8 @@ class GalleryItem extends StatelessWidget {
leading: leading, leading: leading,
title: new Text(title), title: new Text(title),
onTap: () { onTap: () {
if (builder != null) { if (routeName != null)
Navigator.push(context, new MaterialPageRoute<Null>( Navigator.pushNamed(context, routeName);
builder: (BuildContext context) => builder()
));
}
} }
); );
} }
......
...@@ -7,51 +7,22 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -7,51 +7,22 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/main.dart' as material_gallery; import '../lib/main.dart' as material_gallery;
import '../lib/gallery/app.dart' as material_gallery;
import '../lib/gallery/item.dart' as material_gallery;
// Warning: the following strings must be kept in sync with GalleryHome. // Warning: the following strings must be kept in sync with GalleryHome.
const List<String> demoCategories = const <String>['Demos', 'Components', 'Style']; const List<String> demoCategories = const <String>['Demos', 'Components', 'Style'];
const List<String> demoNames = const <String>[
'Weather', Finder findGalleryItemByRouteName(WidgetTester tester, String routeName) {
'Fitness', return find.byPredicate((Widget widget) {
'Fancy lines', return widget is material_gallery.GalleryItem
'Flexible space toolbar', && widget.routeName == routeName;
'Floating action button', });
'Buttons', }
'Cards',
'Chips',
'Date picker',
'Data tables',
'Dialog',
'Drop-down button',
'Expand/collapse list control',
'Grid',
'Icons',
'Leave-behind list items',
'List',
'Menus',
'Modal bottom sheet',
'Over-scroll',
'Page selector',
'Persistent bottom sheet',
'Progress indicators',
'Scrollable tabs',
'Selection controls',
'Sliders',
'Snackbar',
'Tabs',
'Text fields',
'Time picker',
'Tooltips',
'Colors',
'Typography'
];
Finder byTooltip(WidgetTester tester, String message) { Finder byTooltip(WidgetTester tester, String message) {
return find.byElement((Element element) { return find.byPredicate((Widget widget) {
Widget widget = element.widget; return widget is Tooltip && widget.message == message;
if (widget is Tooltip)
return widget.message == message;
return false;
}); });
} }
...@@ -62,12 +33,12 @@ Finder findBackButton(WidgetTester tester) => byTooltip(tester, 'Back'); ...@@ -62,12 +33,12 @@ Finder findBackButton(WidgetTester tester) => byTooltip(tester, 'Back');
// Start a gallery demo and then go back. This function assumes that the // Start a gallery demo and then go back. This function assumes that the
// we're starting on home route and that the submenu that contains the demo // we're starting on home route and that the submenu that contains the demo
// called 'name' is already open. // called 'name' is already open.
void smokeDemo(WidgetTester tester, String menuItemText) { void smokeDemo(WidgetTester tester, String routeName) {
// Ensure that we're (likely to be) on the home page // Ensure that we're (likely to be) on the home page
final Finder navigationMenuButton = findNavigationMenuButton(tester); final Finder menuItem = findGalleryItemByRouteName(tester, routeName);
expect(tester, hasWidget(navigationMenuButton)); expect(tester, hasWidget(menuItem));
tester.tap(find.text(menuItemText)); tester.tap(menuItem);
tester.pump(); // Launch the demo. tester.pump(); // Launch the demo.
tester.pump(const Duration(seconds: 1)); // Wait until the demo has opened. tester.pump(const Duration(seconds: 1)); // Wait until the demo has opened.
...@@ -95,18 +66,18 @@ void main() { ...@@ -95,18 +66,18 @@ void main() {
final List<double> scrollDeltas = new List<double>(); final List<double> scrollDeltas = new List<double>();
double previousY = tester.getTopRight(find.text(demoCategories[0])).y; double previousY = tester.getTopRight(find.text(demoCategories[0])).y;
for (String name in demoNames) { final List<String> routeNames = material_gallery.kRoutes.keys.toList();
final double y = tester.getTopRight(find.text(name)).y; for (String routeName in routeNames) {
final double y = tester.getTopRight(findGalleryItemByRouteName(tester, routeName)).y;
scrollDeltas.add(previousY - y); scrollDeltas.add(previousY - y);
previousY = y; previousY = y;
} }
// Launch each demo and then scroll that item out of the way. // Launch each demo and then scroll that item out of the way.
for (int i = 0; i < demoNames.length; i += 1) { for (int i = 0; i < routeNames.length; i += 1) {
final String name = demoNames[i]; final String routeName = routeNames[i];
print("$name"); smokeDemo(tester, routeName);
smokeDemo(tester, name); tester.scroll(findGalleryItemByRouteName(tester, routeName), new Offset(0.0, scrollDeltas[i]));
tester.scroll(find.text(name), new Offset(0.0, scrollDeltas[i]));
tester.pump(); tester.pump();
} }
......
...@@ -266,6 +266,11 @@ class CommonFinders { ...@@ -266,6 +266,11 @@ class CommonFinders {
/// Finds widgets equal to [config]. /// Finds widgets equal to [config].
Finder byConfig(Widget config) => new _ConfigFinder(config); Finder byConfig(Widget config) => new _ConfigFinder(config);
/// Finds widgets using a [predicate].
Finder byPredicate(WidgetPredicate predicate) {
return new _ElementFinder((Element element) => predicate(element.widget));
}
/// Finds widgets using an element [predicate]. /// Finds widgets using an element [predicate].
Finder byElement(ElementPredicate predicate) => new _ElementFinder(predicate); Finder byElement(ElementPredicate predicate) => new _ElementFinder(predicate);
} }
...@@ -403,6 +408,7 @@ class _ConfigFinder extends Finder { ...@@ -403,6 +408,7 @@ class _ConfigFinder extends Finder {
} }
} }
typedef bool WidgetPredicate(Widget element);
typedef bool ElementPredicate(Element element); typedef bool ElementPredicate(Element element);
class _ElementFinder extends Finder { class _ElementFinder extends Finder {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment