diff --git a/examples/material_gallery/lib/demo/buttons_demo.dart b/examples/material_gallery/lib/demo/buttons_demo.dart index c4e131192c..bafaf7faab 100644 --- a/examples/material_gallery/lib/demo/buttons_demo.dart +++ b/examples/material_gallery/lib/demo/buttons_demo.dart @@ -45,6 +45,8 @@ const String _actionText = const String _actionCode = 'buttons_action'; class ButtonsDemo extends StatefulWidget { + static const String routeName = '/buttons'; + @override _ButtonsDemoState createState() => new _ButtonsDemoState(); } diff --git a/examples/material_gallery/lib/demo/cards_demo.dart b/examples/material_gallery/lib/demo/cards_demo.dart index f8ca31caaf..c3daab2efd 100644 --- a/examples/material_gallery/lib/demo/cards_demo.dart +++ b/examples/material_gallery/lib/demo/cards_demo.dart @@ -118,6 +118,8 @@ class TravelDestinationItem extends StatelessWidget { } class CardsDemo extends StatelessWidget { + static const String routeName = '/cards'; + @override Widget build(BuildContext context) { return new Scaffold( diff --git a/examples/material_gallery/lib/demo/chip_demo.dart b/examples/material_gallery/lib/demo/chip_demo.dart index 39994c4147..08b2ae87f1 100644 --- a/examples/material_gallery/lib/demo/chip_demo.dart +++ b/examples/material_gallery/lib/demo/chip_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class ChipDemo extends StatefulWidget { + static const String routeName = '/chip'; + @override _ChipDemoState createState() => new _ChipDemoState(); } diff --git a/examples/material_gallery/lib/demo/colors_demo.dart b/examples/material_gallery/lib/demo/colors_demo.dart index 04e2687a5c..471b34913d 100644 --- a/examples/material_gallery/lib/demo/colors_demo.dart +++ b/examples/material_gallery/lib/demo/colors_demo.dart @@ -109,6 +109,8 @@ class ColorSwatchTabView extends StatelessWidget { } class ColorsDemo extends StatelessWidget { + static const String routeName = '/colors'; + @override Widget build(BuildContext context) { return new TabBarSelection( diff --git a/examples/material_gallery/lib/demo/data_table_demo.dart b/examples/material_gallery/lib/demo/data_table_demo.dart index 282b1e0da6..62a481fc43 100644 --- a/examples/material_gallery/lib/demo/data_table_demo.dart +++ b/examples/material_gallery/lib/demo/data_table_demo.dart @@ -20,6 +20,8 @@ class Desert { } class DataTableDemo extends StatefulWidget { + static const String routeName = '/data-table'; + @override _DataTableDemoState createState() => new _DataTableDemoState(); } diff --git a/examples/material_gallery/lib/demo/date_picker_demo.dart b/examples/material_gallery/lib/demo/date_picker_demo.dart index 5588b550e4..46744f0740 100644 --- a/examples/material_gallery/lib/demo/date_picker_demo.dart +++ b/examples/material_gallery/lib/demo/date_picker_demo.dart @@ -8,6 +8,8 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; class DatePickerDemo extends StatefulWidget { + static const String routeName = '/date-picker'; + @override _DatePickerDemoState createState() => new _DatePickerDemoState(); } diff --git a/examples/material_gallery/lib/demo/dialog_demo.dart b/examples/material_gallery/lib/demo/dialog_demo.dart index c43b8f6c70..f514a82ad0 100644 --- a/examples/material_gallery/lib/demo/dialog_demo.dart +++ b/examples/material_gallery/lib/demo/dialog_demo.dart @@ -55,6 +55,8 @@ class DialogDemoItem extends StatelessWidget { } class DialogDemo extends StatefulWidget { + static const String routeName = '/dialog'; + @override DialogDemoState createState() => new DialogDemoState(); } diff --git a/examples/material_gallery/lib/demo/drawing_demo.dart b/examples/material_gallery/lib/demo/drawing_demo.dart index 12ec6139d5..9774d52f07 100644 --- a/examples/material_gallery/lib/demo/drawing_demo.dart +++ b/examples/material_gallery/lib/demo/drawing_demo.dart @@ -10,6 +10,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_sprites/flutter_sprites.dart'; class DrawingDemo extends StatefulWidget { + static const String routeName = '/drawing'; + @override _DrawingDemoState createState() => new _DrawingDemoState(); } diff --git a/examples/material_gallery/lib/demo/drop_down_demo.dart b/examples/material_gallery/lib/demo/drop_down_demo.dart index 27872dffee..eeaa119434 100644 --- a/examples/material_gallery/lib/demo/drop_down_demo.dart +++ b/examples/material_gallery/lib/demo/drop_down_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class DropDownDemo extends StatefulWidget { + static const String routeName = '/dropdown'; + @override _DropDownDemoState createState() => new _DropDownDemoState(); } diff --git a/examples/material_gallery/lib/demo/fitness_demo.dart b/examples/material_gallery/lib/demo/fitness_demo.dart index b97314b6a2..cb238ea13b 100644 --- a/examples/material_gallery/lib/demo/fitness_demo.dart +++ b/examples/material_gallery/lib/demo/fitness_demo.dart @@ -16,6 +16,8 @@ SpriteSheet _sprites; class FitnessDemo extends StatelessWidget { FitnessDemo({ Key key }) : super(key: key); + static const String routeName = '/fitness'; + @override Widget build(BuildContext context) { return new Scaffold( diff --git a/examples/material_gallery/lib/demo/flexible_space_demo.dart b/examples/material_gallery/lib/demo/flexible_space_demo.dart index 7fa4d63a64..d63b082144 100644 --- a/examples/material_gallery/lib/demo/flexible_space_demo.dart +++ b/examples/material_gallery/lib/demo/flexible_space_demo.dart @@ -70,6 +70,8 @@ class _ContactItem extends StatelessWidget { } class FlexibleSpaceDemo extends StatefulWidget { + static const String routeName = '/flexible-space'; + @override FlexibleSpaceDemoState createState() => new FlexibleSpaceDemoState(); } diff --git a/examples/material_gallery/lib/demo/grid_list_demo.dart b/examples/material_gallery/lib/demo/grid_list_demo.dart index 3eaa95fd78..89850ae220 100644 --- a/examples/material_gallery/lib/demo/grid_list_demo.dart +++ b/examples/material_gallery/lib/demo/grid_list_demo.dart @@ -132,6 +132,8 @@ class GridDemoPhotoItem extends StatelessWidget { class GridListDemo extends StatefulWidget { GridListDemo({ Key key }) : super(key: key); + static const String routeName = '/grid-list'; + @override GridListDemoState createState() => new GridListDemoState(); } diff --git a/examples/material_gallery/lib/demo/icons_demo.dart b/examples/material_gallery/lib/demo/icons_demo.dart index b42ae7d6a5..b83ef8c542 100644 --- a/examples/material_gallery/lib/demo/icons_demo.dart +++ b/examples/material_gallery/lib/demo/icons_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class IconsDemo extends StatefulWidget { + static const String routeName = '/icons'; + @override IconsDemoState createState() => new IconsDemoState(); } diff --git a/examples/material_gallery/lib/demo/leave_behind_demo.dart b/examples/material_gallery/lib/demo/leave_behind_demo.dart index 277b392c21..9e4ed1880f 100644 --- a/examples/material_gallery/lib/demo/leave_behind_demo.dart +++ b/examples/material_gallery/lib/demo/leave_behind_demo.dart @@ -31,6 +31,8 @@ class LeaveBehindItem implements Comparable { class LeaveBehindDemo extends StatefulWidget { LeaveBehindDemo({ Key key }) : super(key: key); + static const String routeName = '/leave-behind'; + @override LeaveBehindDemoState createState() => new LeaveBehindDemoState(); } diff --git a/examples/material_gallery/lib/demo/list_demo.dart b/examples/material_gallery/lib/demo/list_demo.dart index c35ff72a71..566bf7a45a 100644 --- a/examples/material_gallery/lib/demo/list_demo.dart +++ b/examples/material_gallery/lib/demo/list_demo.dart @@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; class ListDemo extends StatefulWidget { ListDemo({ Key key }) : super(key: key); + static const String routeName = '/list'; + @override ListDemoState createState() => new ListDemoState(); } diff --git a/examples/material_gallery/lib/demo/menu_demo.dart b/examples/material_gallery/lib/demo/menu_demo.dart index e322e77cbe..d872da59fc 100644 --- a/examples/material_gallery/lib/demo/menu_demo.dart +++ b/examples/material_gallery/lib/demo/menu_demo.dart @@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; class MenuDemo extends StatefulWidget { MenuDemo({ Key key }) : super(key: key); + static const String routeName = '/menu'; + @override MenuDemoState createState() => new MenuDemoState(); } diff --git a/examples/material_gallery/lib/demo/modal_bottom_sheet_demo.dart b/examples/material_gallery/lib/demo/modal_bottom_sheet_demo.dart index 9fa24ea88b..d7dddb8c3f 100644 --- a/examples/material_gallery/lib/demo/modal_bottom_sheet_demo.dart +++ b/examples/material_gallery/lib/demo/modal_bottom_sheet_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class ModalBottomSheetDemo extends StatelessWidget { + static const String routeName = '/modal-bottom-sheet'; + final TextStyle textStyle = new TextStyle( color: Colors.indigo[400], fontSize: 24.0, diff --git a/examples/material_gallery/lib/demo/overscroll_demo.dart b/examples/material_gallery/lib/demo/overscroll_demo.dart index 3dd532e250..3ee1f02d1a 100644 --- a/examples/material_gallery/lib/demo/overscroll_demo.dart +++ b/examples/material_gallery/lib/demo/overscroll_demo.dart @@ -11,6 +11,8 @@ enum IndicatorType { overscroll, refresh } class OverscrollDemo extends StatefulWidget { OverscrollDemo({ Key key }) : super(key: key); + static const String routeName = '/overscroll'; + @override OverscrollDemoState createState() => new OverscrollDemoState(); } diff --git a/examples/material_gallery/lib/demo/page_selector_demo.dart b/examples/material_gallery/lib/demo/page_selector_demo.dart index efb48b315b..7b7f0b9d3e 100644 --- a/examples/material_gallery/lib/demo/page_selector_demo.dart +++ b/examples/material_gallery/lib/demo/page_selector_demo.dart @@ -6,6 +6,8 @@ import 'package:flutter/material.dart'; class PageSelectorDemo extends StatelessWidget { + static const String routeName = '/page-selector'; + void _handleArrowButtonPress(BuildContext context, int delta) { final TabBarSelectionState selection = TabBarSelection.of/**/(context); if (!selection.valueIsChanging) diff --git a/examples/material_gallery/lib/demo/persistent_bottom_sheet_demo.dart b/examples/material_gallery/lib/demo/persistent_bottom_sheet_demo.dart index 917aeb06d0..242c8d7e85 100644 --- a/examples/material_gallery/lib/demo/persistent_bottom_sheet_demo.dart +++ b/examples/material_gallery/lib/demo/persistent_bottom_sheet_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class PersistentBottomSheetDemo extends StatefulWidget { + static const String routeName = '/persistent-bottom-sheet'; + @override _PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState(); } diff --git a/examples/material_gallery/lib/demo/progress_indicator_demo.dart b/examples/material_gallery/lib/demo/progress_indicator_demo.dart index 2040ddb00f..8c4e363e65 100644 --- a/examples/material_gallery/lib/demo/progress_indicator_demo.dart +++ b/examples/material_gallery/lib/demo/progress_indicator_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class ProgressIndicatorDemo extends StatefulWidget { + static const String routeName = '/progress-indicator'; + @override _ProgressIndicatorDemoState createState() => new _ProgressIndicatorDemoState(); } diff --git a/examples/material_gallery/lib/demo/scrollable_tabs_demo.dart b/examples/material_gallery/lib/demo/scrollable_tabs_demo.dart index d5de3d7b70..2f00f0e3e6 100644 --- a/examples/material_gallery/lib/demo/scrollable_tabs_demo.dart +++ b/examples/material_gallery/lib/demo/scrollable_tabs_demo.dart @@ -11,6 +11,8 @@ enum TabsDemoStyle { } class ScrollableTabsDemo extends StatefulWidget { + static const String routeName = '/scrollable-tabs'; + @override ScrollableTabsDemoState createState() => new ScrollableTabsDemoState(); } diff --git a/examples/material_gallery/lib/demo/selection_controls_demo.dart b/examples/material_gallery/lib/demo/selection_controls_demo.dart index 92e440d6d1..69936fd0a0 100644 --- a/examples/material_gallery/lib/demo/selection_controls_demo.dart +++ b/examples/material_gallery/lib/demo/selection_controls_demo.dart @@ -29,6 +29,8 @@ const String _switchText = const String _switchCode = 'selectioncontrols_switch'; class SelectionControlsDemo extends StatefulWidget { + static const String routeName = '/selection-controls'; + @override _SelectionControlsDemoState createState() => new _SelectionControlsDemoState(); } diff --git a/examples/material_gallery/lib/demo/slider_demo.dart b/examples/material_gallery/lib/demo/slider_demo.dart index 7ce44cffe8..78d40eee05 100644 --- a/examples/material_gallery/lib/demo/slider_demo.dart +++ b/examples/material_gallery/lib/demo/slider_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class SliderDemo extends StatefulWidget { + static const String routeName = '/slider'; + @override _SliderDemoState createState() => new _SliderDemoState(); } diff --git a/examples/material_gallery/lib/demo/snack_bar_demo.dart b/examples/material_gallery/lib/demo/snack_bar_demo.dart index 55a068aa58..f0ed109bad 100644 --- a/examples/material_gallery/lib/demo/snack_bar_demo.dart +++ b/examples/material_gallery/lib/demo/snack_bar_demo.dart @@ -20,6 +20,8 @@ const String _text3 = class SnackBarDemo extends StatefulWidget { SnackBarDemo({ Key key }) : super(key: key); + static const String routeName = '/snack-bar'; + @override _SnackBarDemoState createState() => new _SnackBarDemoState(); } diff --git a/examples/material_gallery/lib/demo/tabs_demo.dart b/examples/material_gallery/lib/demo/tabs_demo.dart index 0fb5ddd253..ab26272b5d 100644 --- a/examples/material_gallery/lib/demo/tabs_demo.dart +++ b/examples/material_gallery/lib/demo/tabs_demo.dart @@ -19,6 +19,8 @@ final List<_Page> _pages = <_Page>[ ]; class TabsDemo extends StatefulWidget { + static const String routeName = '/tabs'; + @override TabsDemoState createState() => new TabsDemoState(); } diff --git a/examples/material_gallery/lib/demo/tabs_fab_demo.dart b/examples/material_gallery/lib/demo/tabs_fab_demo.dart index 9fe05821f3..5c32c09e2c 100644 --- a/examples/material_gallery/lib/demo/tabs_fab_demo.dart +++ b/examples/material_gallery/lib/demo/tabs_fab_demo.dart @@ -26,6 +26,8 @@ const String _explanatoryText = "by its key."; class TabsFabDemo extends StatefulWidget { + static const String routeName = '/tabs-fab'; + @override _TabsFabDemoState createState() => new _TabsFabDemoState(); } diff --git a/examples/material_gallery/lib/demo/text_field_demo.dart b/examples/material_gallery/lib/demo/text_field_demo.dart index 1f78b42216..ec991537fd 100644 --- a/examples/material_gallery/lib/demo/text_field_demo.dart +++ b/examples/material_gallery/lib/demo/text_field_demo.dart @@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; class TextFieldDemo extends StatefulWidget { TextFieldDemo({ Key key }) : super(key: key); + static const String routeName = '/text-field'; + @override TextFieldDemoState createState() => new TextFieldDemoState(); } diff --git a/examples/material_gallery/lib/demo/time_picker_demo.dart b/examples/material_gallery/lib/demo/time_picker_demo.dart index be629631d4..df1fb0c8a6 100644 --- a/examples/material_gallery/lib/demo/time_picker_demo.dart +++ b/examples/material_gallery/lib/demo/time_picker_demo.dart @@ -7,6 +7,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; class TimePickerDemo extends StatefulWidget { + static const String routeName = '/time-picker'; + @override _TimePickerDemoState createState() => new _TimePickerDemoState(); } diff --git a/examples/material_gallery/lib/demo/tooltip_demo.dart b/examples/material_gallery/lib/demo/tooltip_demo.dart index 2028209a30..815186491a 100644 --- a/examples/material_gallery/lib/demo/tooltip_demo.dart +++ b/examples/material_gallery/lib/demo/tooltip_demo.dart @@ -10,6 +10,9 @@ const String _introText = "apps accessible, like screen readers."; class TooltipDemo extends StatelessWidget { + + static const String routeName = '/tooltip'; + @override Widget build(BuildContext context) { final ThemeData theme = Theme.of(context); diff --git a/examples/material_gallery/lib/demo/two_level_list_demo.dart b/examples/material_gallery/lib/demo/two_level_list_demo.dart index ac6f7cc8da..215fb06f42 100644 --- a/examples/material_gallery/lib/demo/two_level_list_demo.dart +++ b/examples/material_gallery/lib/demo/two_level_list_demo.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; class TwoLevelListDemo extends StatelessWidget { + static const String routeName = '/two-level-list'; + @override Widget build(BuildContext context) { return new Scaffold( diff --git a/examples/material_gallery/lib/demo/typography_demo.dart b/examples/material_gallery/lib/demo/typography_demo.dart index 44a2ff34df..5f3b7e0f94 100644 --- a/examples/material_gallery/lib/demo/typography_demo.dart +++ b/examples/material_gallery/lib/demo/typography_demo.dart @@ -39,6 +39,8 @@ class TextStyleItem extends StatelessWidget { } class TypographyDemo extends StatelessWidget { + static const String routeName = '/typography'; + @override Widget build(BuildContext context) { final TextTheme textTheme = Theme.of(context).textTheme; diff --git a/examples/material_gallery/lib/demo/weather_demo.dart b/examples/material_gallery/lib/demo/weather_demo.dart index 559591e232..0c6b852df3 100644 --- a/examples/material_gallery/lib/demo/weather_demo.dart +++ b/examples/material_gallery/lib/demo/weather_demo.dart @@ -20,6 +20,8 @@ enum WeatherType { class WeatherDemo extends StatefulWidget { WeatherDemo({ Key key }) : super(key: key); + static const String routeName = '/weather'; + @override _WeatherDemoState createState() => new _WeatherDemoState(); } diff --git a/examples/material_gallery/lib/demos.dart b/examples/material_gallery/lib/demos.dart new file mode 100644 index 0000000000..5d48384a68 --- /dev/null +++ b/examples/material_gallery/lib/demos.dart @@ -0,0 +1,37 @@ +// 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'; diff --git a/examples/material_gallery/lib/gallery/app.dart b/examples/material_gallery/lib/gallery/app.dart index f9e8007599..4fd6ab455b 100644 --- a/examples/material_gallery/lib/gallery/app.dart +++ b/examples/material_gallery/lib/gallery/app.dart @@ -5,8 +5,45 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart' show timeDilation; +import '../demos.dart'; import 'home.dart'; +final Map kRoutes = { + 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 { GalleryApp({ Key key }) : super(key: key); @@ -24,6 +61,7 @@ class GalleryAppState extends State { title: 'Flutter Material Gallery', theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme, showPerformanceOverlay: _showPerformanceOverlay, + routes: kRoutes, home: new GalleryHome( useLightTheme: _useLightTheme, onThemeChanged: (bool value) { setState(() { _useLightTheme = value; }); }, diff --git a/examples/material_gallery/lib/gallery/header.dart b/examples/material_gallery/lib/gallery/header.dart index fcfb0dd1c1..4db1488a70 100644 --- a/examples/material_gallery/lib/gallery/header.dart +++ b/examples/material_gallery/lib/gallery/header.dart @@ -1,3 +1,7 @@ +// 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 'package:flutter/material.dart'; diff --git a/examples/material_gallery/lib/gallery/home.dart b/examples/material_gallery/lib/gallery/home.dart index ad95f9db2f..a8125ead7a 100644 --- a/examples/material_gallery/lib/gallery/home.dart +++ b/examples/material_gallery/lib/gallery/home.dart @@ -5,44 +5,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import '../demos.dart'; import 'drawer.dart'; import 'header.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; class GalleryHome extends StatefulWidget { @@ -106,51 +73,51 @@ class GalleryHomeState extends State { leading: new Icon(icon: Icons.star), title: new Text('Demos'), children: [ - new GalleryItem(title: 'Weather', builder: () => new WeatherDemo()), - new GalleryItem(title: 'Fitness', builder: () => new FitnessDemo()), - new GalleryItem(title: 'Fancy lines', builder: () => new DrawingDemo()), - new GalleryItem(title: 'Flexible space toolbar', builder: () => new FlexibleSpaceDemo()), - new GalleryItem(title: 'Floating action button', builder: () => new TabsFabDemo()), + new GalleryItem(title: 'Weather', routeName: WeatherDemo.routeName), + new GalleryItem(title: 'Fitness', routeName: FitnessDemo.routeName), + new GalleryItem(title: 'Fancy lines', routeName: DrawingDemo.routeName), + new GalleryItem(title: 'Flexible space toolbar', routeName: FlexibleSpaceDemo.routeName), + new GalleryItem(title: 'Floating action button', routeName: TabsFabDemo.routeName), ] ), new TwoLevelSublist( leading: new Icon(icon: Icons.extension), title: new Text('Components'), children: [ - new GalleryItem(title: 'Buttons', builder: () => new ButtonsDemo()), - new GalleryItem(title: 'Cards', builder: () => new CardsDemo()), - new GalleryItem(title: 'Chips', builder: () => new ChipDemo()), - new GalleryItem(title: 'Date picker', builder: () => new DatePickerDemo()), - new GalleryItem(title: 'Data tables', builder: () => new DataTableDemo()), - new GalleryItem(title: 'Dialog', builder: () => new DialogDemo()), - new GalleryItem(title: 'Drop-down button', builder: () => new DropDownDemo()), - new GalleryItem(title: 'Expand/collapse list control', builder: () => new TwoLevelListDemo()), - new GalleryItem(title: 'Grid', builder: () => new GridListDemo()), - new GalleryItem(title: 'Icons', builder: () => new IconsDemo()), - new GalleryItem(title: 'Leave-behind list items', builder: () => new LeaveBehindDemo()), - new GalleryItem(title: 'List', builder: () => new ListDemo()), - new GalleryItem(title: 'Menus', builder: () => new MenuDemo()), - new GalleryItem(title: 'Modal bottom sheet', builder: () => new ModalBottomSheetDemo()), - new GalleryItem(title: 'Over-scroll', builder: () => new OverscrollDemo()), - new GalleryItem(title: 'Page selector', builder: () => new PageSelectorDemo()), - new GalleryItem(title: 'Persistent bottom sheet', builder: () => new PersistentBottomSheetDemo()), - new GalleryItem(title: 'Progress indicators', builder: () => new ProgressIndicatorDemo()), - new GalleryItem(title: 'Scrollable tabs', builder: () => new ScrollableTabsDemo()), - new GalleryItem(title: 'Selection controls', builder: () => new SelectionControlsDemo()), - new GalleryItem(title: 'Sliders', builder: () => new SliderDemo()), - new GalleryItem(title: 'Snackbar', builder: () => new SnackBarDemo()), - new GalleryItem(title: 'Tabs', builder: () => new TabsDemo()), - new GalleryItem(title: 'Text fields', builder: () => new TextFieldDemo()), - new GalleryItem(title: 'Time picker', builder: () => new TimePickerDemo()), - new GalleryItem(title: 'Tooltips', builder: () => new TooltipDemo()), + new GalleryItem(title: 'Buttons', routeName: ButtonsDemo.routeName), + new GalleryItem(title: 'Cards', routeName: CardsDemo.routeName), + new GalleryItem(title: 'Chips', routeName: ChipDemo.routeName), + new GalleryItem(title: 'Date picker', routeName: DatePickerDemo.routeName), + new GalleryItem(title: 'Data tables', routeName: DataTableDemo.routeName), + new GalleryItem(title: 'Dialog', routeName: DialogDemo.routeName), + new GalleryItem(title: 'Drop-down button', routeName: DropDownDemo.routeName), + new GalleryItem(title: 'Expand/collapse list control', routeName: TwoLevelListDemo.routeName), + new GalleryItem(title: 'Grid', routeName: GridListDemo.routeName), + new GalleryItem(title: 'Icons', routeName: IconsDemo.routeName), + new GalleryItem(title: 'Leave-behind list items', routeName: LeaveBehindDemo.routeName), + new GalleryItem(title: 'List', routeName: ListDemo.routeName), + new GalleryItem(title: 'Menus', routeName: MenuDemo.routeName), + new GalleryItem(title: 'Modal bottom sheet', routeName: ModalBottomSheetDemo.routeName), + new GalleryItem(title: 'Over-scroll', routeName: OverscrollDemo.routeName), + new GalleryItem(title: 'Page selector', routeName: PageSelectorDemo.routeName), + new GalleryItem(title: 'Persistent bottom sheet', routeName: PersistentBottomSheetDemo.routeName), + new GalleryItem(title: 'Progress indicators', routeName: ProgressIndicatorDemo.routeName), + new GalleryItem(title: 'Scrollable tabs', routeName: ScrollableTabsDemo.routeName), + new GalleryItem(title: 'Selection controls', routeName: SelectionControlsDemo.routeName), + new GalleryItem(title: 'Sliders', routeName: SliderDemo.routeName), + new GalleryItem(title: 'Snackbar', routeName: SnackBarDemo.routeName), + new GalleryItem(title: 'Tabs', routeName: TabsDemo.routeName), + new GalleryItem(title: 'Text fields', routeName: TextFieldDemo.routeName), + new GalleryItem(title: 'Time picker', routeName: TimePickerDemo.routeName), + new GalleryItem(title: 'Tooltips', routeName: TooltipDemo.routeName), ] ), new TwoLevelSublist( leading: new Icon(icon: Icons.color_lens), title: new Text('Style'), children: [ - new GalleryItem(title: 'Colors', builder: () => new ColorsDemo()), - new GalleryItem(title: 'Typography', builder: () => new TypographyDemo()), + new GalleryItem(title: 'Colors', routeName: ColorsDemo.routeName), + new GalleryItem(title: 'Typography', routeName: TypographyDemo.routeName), ] ) ] diff --git a/examples/material_gallery/lib/gallery/item.dart b/examples/material_gallery/lib/gallery/item.dart index 06510685d6..d80a7382a3 100644 --- a/examples/material_gallery/lib/gallery/item.dart +++ b/examples/material_gallery/lib/gallery/item.dart @@ -1,13 +1,17 @@ +// 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'; typedef Widget GalleryDemoBuilder(); class GalleryItem extends StatelessWidget { - GalleryItem({ this.title, this.icon, this.builder }); + GalleryItem({ this.title, this.icon, this.routeName }); final String title; final IconData icon; - final GalleryDemoBuilder builder; + final String routeName; @override Widget build(BuildContext context) { @@ -17,11 +21,8 @@ class GalleryItem extends StatelessWidget { leading: leading, title: new Text(title), onTap: () { - if (builder != null) { - Navigator.push(context, new MaterialPageRoute( - builder: (BuildContext context) => builder() - )); - } + if (routeName != null) + Navigator.pushNamed(context, routeName); } ); } diff --git a/examples/material_gallery/test/smoke_test.dart b/examples/material_gallery/test/smoke_test.dart index 6f546327ec..354f4a57d9 100644 --- a/examples/material_gallery/test/smoke_test.dart +++ b/examples/material_gallery/test/smoke_test.dart @@ -7,51 +7,22 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:test/test.dart'; 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. const List demoCategories = const ['Demos', 'Components', 'Style']; -const List demoNames = const [ - 'Weather', - 'Fitness', - 'Fancy lines', - 'Flexible space toolbar', - '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 findGalleryItemByRouteName(WidgetTester tester, String routeName) { + return find.byPredicate((Widget widget) { + return widget is material_gallery.GalleryItem + && widget.routeName == routeName; + }); +} Finder byTooltip(WidgetTester tester, String message) { - return find.byElement((Element element) { - Widget widget = element.widget; - if (widget is Tooltip) - return widget.message == message; - return false; + return find.byPredicate((Widget widget) { + return widget is Tooltip && widget.message == message; }); } @@ -62,12 +33,12 @@ Finder findBackButton(WidgetTester tester) => byTooltip(tester, 'Back'); // 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 // 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 - final Finder navigationMenuButton = findNavigationMenuButton(tester); - expect(tester, hasWidget(navigationMenuButton)); + final Finder menuItem = findGalleryItemByRouteName(tester, routeName); + expect(tester, hasWidget(menuItem)); - tester.tap(find.text(menuItemText)); + tester.tap(menuItem); tester.pump(); // Launch the demo. tester.pump(const Duration(seconds: 1)); // Wait until the demo has opened. @@ -95,18 +66,18 @@ void main() { final List scrollDeltas = new List(); double previousY = tester.getTopRight(find.text(demoCategories[0])).y; - for (String name in demoNames) { - final double y = tester.getTopRight(find.text(name)).y; + final List routeNames = material_gallery.kRoutes.keys.toList(); + for (String routeName in routeNames) { + final double y = tester.getTopRight(findGalleryItemByRouteName(tester, routeName)).y; scrollDeltas.add(previousY - y); previousY = y; } // Launch each demo and then scroll that item out of the way. - for (int i = 0; i < demoNames.length; i += 1) { - final String name = demoNames[i]; - print("$name"); - smokeDemo(tester, name); - tester.scroll(find.text(name), new Offset(0.0, scrollDeltas[i])); + for (int i = 0; i < routeNames.length; i += 1) { + final String routeName = routeNames[i]; + smokeDemo(tester, routeName); + tester.scroll(findGalleryItemByRouteName(tester, routeName), new Offset(0.0, scrollDeltas[i])); tester.pump(); } diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 26ebbf2cd2..35b5dee828 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -266,6 +266,11 @@ class CommonFinders { /// Finds widgets equal to [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]. Finder byElement(ElementPredicate predicate) => new _ElementFinder(predicate); } @@ -403,6 +408,7 @@ class _ConfigFinder extends Finder { } } +typedef bool WidgetPredicate(Widget element); typedef bool ElementPredicate(Element element); class _ElementFinder extends Finder {