Add API docs link to each gallery demo (#22379)

This commit is contained in:
xster 2018-09-28 16:06:41 -07:00 committed by GitHub
parent c60560fb16
commit 75b24070dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 300 additions and 35 deletions

View File

@ -3,18 +3,21 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class CupertinoProgressIndicatorDemo extends StatelessWidget {
static const String routeName = '/cupertino/progress_indicator';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cupertino Activity Indicator'),
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
previousPageTitle: 'Cupertino',
middle: const Text('Cupertino Activity Indicator'),
trailing: CupertinoDemoDocumentationButton(routeName),
),
body: const Center(
child: const Center(
child: CupertinoActivityIndicator(),
),
);

View File

@ -5,6 +5,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class CupertinoAlertDemo extends StatefulWidget {
static const String routeName = '/cupertino/alert';
@ -53,6 +55,7 @@ class _CupertinoAlertDemoState extends State<CupertinoAlertDemo> {
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Cupertino Alerts'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoAlertDemo.routeName)],
),
body: ListView(
padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 72.0),

View File

@ -5,6 +5,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class CupertinoButtonsDemo extends StatefulWidget {
static const String routeName = '/cupertino/buttons';
@ -20,6 +22,7 @@ class _CupertinoButtonDemoState extends State<CupertinoButtonsDemo> {
return Scaffold(
appBar: AppBar(
title: const Text('Cupertino Buttons'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoButtonsDemo.routeName)],
),
body: Column(
children: <Widget> [

View File

@ -8,6 +8,8 @@ import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
const List<Color> coolColors = <Color>[
@ -125,6 +127,15 @@ class ExitButton extends StatelessWidget {
}
}
final Widget trailingButtons = Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CupertinoDemoDocumentationButton(CupertinoNavigationDemo.routeName),
const Padding(padding: EdgeInsets.only(left: 8.0)),
const ExitButton(),
],
);
class CupertinoDemoTab1 extends StatelessWidget {
const CupertinoDemoTab1({this.colorItems, this.colorNameItems});
@ -136,8 +147,8 @@ class CupertinoDemoTab1 extends StatelessWidget {
return CupertinoPageScaffold(
child: CustomScrollView(
slivers: <Widget>[
const CupertinoSliverNavigationBar(
trailing: ExitButton(),
CupertinoSliverNavigationBar(
trailing: trailingButtons,
),
SliverPadding(
// Top media padding consumed by CupertinoSliverNavigationBar.
@ -421,8 +432,8 @@ class CupertinoDemoTab2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
trailing: ExitButton(),
navigationBar: CupertinoNavigationBar(
trailing: trailingButtons,
),
child: ListView(
children: <Widget>[
@ -704,8 +715,8 @@ class CupertinoDemoTab3 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
trailing: ExitButton(),
navigationBar: CupertinoNavigationBar(
trailing: trailingButtons,
),
child: DecoratedBox(
decoration: const BoxDecoration(color: Color(0xFFEFEFF4)),

View File

@ -4,6 +4,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
import 'cupertino_navigation_demo.dart' show coolColorNames;
const double _kPickerSheetHeight = 216.0;
@ -132,6 +133,7 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
return Scaffold(
appBar: AppBar(
title: const Text('Cupertino Picker'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoPickerDemo.routeName)],
),
body: DefaultTextStyle(
style: const TextStyle(

View File

@ -6,6 +6,8 @@ import 'dart:math' show Random;
import 'package:flutter/cupertino.dart';
import '../../gallery/demo.dart';
class CupertinoRefreshControlDemo extends StatefulWidget {
static const String routeName = '/cupertino/refresh';
@ -48,9 +50,10 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem
decoration: const BoxDecoration(color: Color(0xFFEFEFF4)),
child: CustomScrollView(
slivers: <Widget>[
const CupertinoSliverNavigationBar(
largeTitle: Text('Cupertino Refresh'),
CupertinoSliverNavigationBar(
largeTitle: const Text('Cupertino Refresh'),
previousPageTitle: 'Cupertino',
trailing: CupertinoDemoDocumentationButton(CupertinoRefreshControlDemo.routeName),
),
CupertinoSliverRefreshControl(
onRefresh: () {

View File

@ -5,6 +5,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const Color _kKeyUmbraOpacity = Color(0x33000000); // alpha = 0.2
const Color _kKeyPenumbraOpacity = Color(0x24000000); // alpha = 0.14
const Color _kAmbientShadowOpacity = Color(0x1F000000); // alpha = 0.12
@ -51,6 +53,7 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
return Scaffold(
appBar: AppBar(
title: const Text('Segmented Control'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoSegmentedControlDemo.routeName)],
),
body: Column(
children: <Widget>[

View File

@ -5,6 +5,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class CupertinoSliderDemo extends StatefulWidget {
static const String routeName = '/cupertino/slider';
@ -21,6 +23,7 @@ class _CupertinoSliderDemoState extends State<CupertinoSliderDemo> {
return Scaffold(
appBar: AppBar(
title: const Text('Cupertino Sliders'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoSliderDemo.routeName)],
),
body: Center(
child: Column(

View File

@ -5,6 +5,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class CupertinoSwitchDemo extends StatefulWidget {
static const String routeName = '/cupertino/switch';
@ -21,6 +23,7 @@ class _CupertinoSwitchDemoState extends State<CupertinoSwitchDemo> {
return Scaffold(
appBar: AppBar(
title: const Text('Cupertino Switch'),
actions: <Widget>[MaterialDemoDocumentationButton(CupertinoSwitchDemo.routeName)],
),
body: Center(
child: Column(

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class BottomAppBarDemo extends StatefulWidget {
static const String routeName = '/material/bottom_app_bar';
@ -143,6 +145,7 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
title: const Text('Bottom app bar'),
elevation: 0.0,
actions: <Widget>[
MaterialDemoDocumentationButton(BottomAppBarDemo.routeName),
IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class NavigationIconView {
NavigationIconView({
Widget icon,
@ -209,6 +211,7 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
appBar: AppBar(
title: const Text('Bottom navigation'),
actions: <Widget>[
MaterialDemoDocumentationButton(BottomNavigationDemo.routeName),
PopupMenuButton<BottomNavigationBarType>(
onSelected: (BottomNavigationBarType value) {
setState(() {

View File

@ -70,6 +70,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
child: buildRaisedButton(),
),
exampleCodeTag: _raisedCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/RaisedButton-class.html',
),
ComponentDemoTabData(
tabName: 'FLAT',
@ -79,6 +80,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
child: buildFlatButton(),
),
exampleCodeTag: _flatCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/FlatButton-class.html',
),
ComponentDemoTabData(
tabName: 'OUTLINE',
@ -88,24 +90,28 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
child: buildOutlineButton(),
),
exampleCodeTag: _outlineCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/OutlineButton-class.html',
),
ComponentDemoTabData(
tabName: 'DROPDOWN',
description: _dropdownText,
demoWidget: buildDropdownButton(),
exampleCodeTag: _dropdownCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/DropdownButton-class.html',
),
ComponentDemoTabData(
tabName: 'ICON',
description: _iconText,
demoWidget: buildIconButton(),
exampleCodeTag: _iconCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/IconButton-class.html',
),
ComponentDemoTabData(
tabName: 'ACTION',
description: _actionText,
demoWidget: buildActionButton(),
exampleCodeTag: _actionCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/FloatingActionButton-class.html',
),
];

View File

@ -5,6 +5,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
class TravelDestination {
@ -168,6 +170,7 @@ class _CardsDemoState extends State<CardsDemo> {
appBar: AppBar(
title: const Text('Travel stream'),
actions: <Widget>[
MaterialDemoDocumentationButton(CardsDemo.routeName),
IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const List<String> _defaultMaterials = <String>[
'poker',
'tortilla',
@ -303,6 +305,7 @@ class _ChipDemoState extends State<ChipDemo> {
appBar: AppBar(
title: const Text('Chips'),
actions: <Widget>[
MaterialDemoDocumentationButton(ChipDemo.routeName),
IconButton(
onPressed: () {
setState(() {

View File

@ -5,6 +5,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import '../../gallery/demo.dart';
class Dessert {
Dessert(this.name, this.calories, this.fat, this.carbs, this.protein, this.sodium, this.calcium, this.iron);
final String name;
@ -164,7 +166,12 @@ class _DataTableDemoState extends State<DataTableDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Data tables')),
appBar: AppBar(
title: const Text('Data tables'),
actions: <Widget>[
MaterialDemoDocumentationButton(DataTableDemo.routeName),
],
),
body: ListView(
padding: const EdgeInsets.all(20.0),
children: <Widget>[

View File

@ -7,6 +7,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../../gallery/demo.dart';
class _InputDropdown extends StatelessWidget {
const _InputDropdown({
Key key,
@ -129,7 +131,10 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Date and time pickers')),
appBar: AppBar(
title: const Text('Date and time pickers'),
actions: <Widget>[MaterialDemoDocumentationButton(DateAndTimePickerDemo.routeName)],
),
body: DropdownButtonHideUnderline(
child: SafeArea(
top: false,

View File

@ -4,6 +4,7 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
import 'full_screen_dialog_demo.dart';
enum DialogDemoAction {
@ -87,7 +88,8 @@ class DialogDemoState extends State<DialogDemo> {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Dialogs')
title: const Text('Dialogs'),
actions: <Widget>[MaterialDemoDocumentationButton(DialogDemo.routeName)],
),
body: ListView(
padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 72.0),

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _kAsset0 = 'people/square/trevor.png';
const String _kAsset1 = 'people/square/stella.png';
const String _kAsset2 = 'people/square/sandra.png';
@ -88,6 +90,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
},
),
title: const Text('Navigation drawer'),
actions: <Widget>[MaterialDemoDocumentationButton(DrawerDemo.routeName)],
),
drawer: Drawer(
child: Column(

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class ElevationDemo extends StatefulWidget {
static const String routeName = '/material/elevation';
@ -46,6 +48,7 @@ class _ElevationDemoState extends State<ElevationDemo> {
appBar: AppBar(
title: const Text('Elevation'),
actions: <Widget>[
MaterialDemoDocumentationButton(ElevationDemo.routeName),
IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
enum _Location {
Barbados,
Bahamas,
@ -336,7 +338,12 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Expansion panels')),
appBar: AppBar(
title: const Text('Expansion panels'),
actions: <Widget>[
MaterialDemoDocumentationButton(ExpansionPanelsDemo.routeName),
],
),
body: SingleChildScrollView(
child: SafeArea(
top: false,

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
enum GridDemoTileStyle {
imageOnly,
oneLine,
@ -340,6 +342,7 @@ class GridListDemoState extends State<GridListDemo> {
appBar: AppBar(
title: const Text('Grid list'),
actions: <Widget>[
MaterialDemoDocumentationButton(GridListDemo.routeName),
PopupMenuButton<GridDemoTileStyle>(
onSelected: changeTileStyle,
itemBuilder: (BuildContext context) => <PopupMenuItem<GridDemoTileStyle>>[

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class IconsDemo extends StatefulWidget {
static const String routeName = '/material/icons';
@ -48,7 +50,8 @@ class IconsDemoState extends State<IconsDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Icons')
title: const Text('Icons'),
actions: <Widget>[MaterialDemoDocumentationButton(IconsDemo.routeName)],
),
body: IconTheme(
data: IconThemeData(color: iconColor),

View File

@ -7,6 +7,8 @@ import 'package:collection/collection.dart' show lowerBound;
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import '../../gallery/demo.dart';
enum LeaveBehindDemoAction {
reset,
horizontalSwipe,
@ -140,6 +142,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
appBar: AppBar(
title: const Text('Swipe to dismiss'),
actions: <Widget>[
MaterialDemoDocumentationButton(LeaveBehindDemo.routeName),
PopupMenuButton<LeaveBehindDemoAction>(
onSelected: handleDemoAction,
itemBuilder: (BuildContext context) => <PopupMenuEntry<LeaveBehindDemoAction>>[

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
enum _MaterialListType {
/// A list tile that contains a single line of text.
oneLine,
@ -216,6 +218,7 @@ class _ListDemoState extends State<ListDemo> {
appBar: AppBar(
title: Text('Scrolling list\n$itemTypeText$layoutText'),
actions: <Widget>[
MaterialDemoDocumentationButton(ListDemo.routeName),
IconButton(
icon: const Icon(Icons.sort_by_alpha),
tooltip: 'Sort',

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class MenuDemo extends StatefulWidget {
const MenuDemo({ Key key }) : super(key: key);
@ -64,6 +66,7 @@ class MenuDemoState extends State<MenuDemo> {
appBar: AppBar(
title: const Text('Menus'),
actions: <Widget>[
MaterialDemoDocumentationButton(MenuDemo.routeName),
PopupMenuButton<String>(
onSelected: showMenuSelection,
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[

View File

@ -4,13 +4,18 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class ModalBottomSheetDemo extends StatelessWidget {
static const String routeName = '/material/modal-bottom-sheet';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Modal bottom sheet')),
appBar: AppBar(
title: const Text('Modal bottom sheet'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: Center(
child: RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),

View File

@ -6,6 +6,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
enum IndicatorType { overscroll, refresh }
class OverscrollDemo extends StatefulWidget {
@ -47,6 +49,7 @@ class OverscrollDemoState extends State<OverscrollDemo> {
appBar: AppBar(
title: const Text('Pull to refresh'),
actions: <Widget>[
MaterialDemoDocumentationButton(OverscrollDemo.routeName),
IconButton(
icon: const Icon(Icons.refresh),
tooltip: 'Refresh',

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class _PageSelector extends StatelessWidget {
const _PageSelector({ this.icons });
@ -85,7 +87,10 @@ class PageSelectorDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Page selector')),
appBar: AppBar(
title: const Text('Page selector'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: DefaultTabController(
length: icons.length,
child: _PageSelector(icons: icons),

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class PersistentBottomSheetDemo extends StatefulWidget {
static const String routeName = '/material/persistent-bottom-sheet';
@ -76,7 +78,12 @@ class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(title: const Text('Persistent bottom sheet')),
appBar: AppBar(
title: const Text('Persistent bottom sheet'),
actions: <Widget>[
MaterialDemoDocumentationButton(PersistentBottomSheetDemo.routeName),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _showMessage,
backgroundColor: Colors.redAccent,

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class ProgressIndicatorDemo extends StatefulWidget {
static const String routeName = '/material/progress-indicator';
@ -100,7 +102,10 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Progress indicators')),
appBar: AppBar(
title: const Text('Progress indicators'),
actions: <Widget>[MaterialDemoDocumentationButton(ProgressIndicatorDemo.routeName)],
),
body: Center(
child: SingleChildScrollView(
child: DefaultTextStyle(

View File

@ -6,6 +6,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import '../../gallery/demo.dart';
enum _ReorderableListType {
/// A list tile that contains a [CircleAvatar].
horizontalAvatar,
@ -157,6 +159,7 @@ class _ListDemoState extends State<ReorderableListDemo> {
appBar: AppBar(
title: const Text('Reorderable list'),
actions: <Widget>[
MaterialDemoDocumentationButton(ReorderableListDemo.routeName),
IconButton(
icon: const Icon(Icons.sort_by_alpha),
tooltip: 'Sort',

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
enum TabsDemoStyle {
iconsAndText,
iconsOnly,
@ -125,6 +127,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
appBar: AppBar(
title: const Text('Scrollable tabs'),
actions: <Widget>[
MaterialDemoDocumentationButton(ScrollableTabsDemo.routeName),
IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class SearchDemo extends StatefulWidget {
static const String routeName = '/material/search';
@ -50,6 +52,7 @@ class _SearchDemoState extends State<SearchDemo> {
}
},
),
MaterialDemoDocumentationButton(SearchDemo.routeName),
IconButton(
tooltip: 'More (not implemented)',
icon: Icon(

View File

@ -42,19 +42,22 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
tabName: 'CHECKBOX',
description: _checkboxText,
demoWidget: buildCheckbox(),
exampleCodeTag: _checkboxCode
exampleCodeTag: _checkboxCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/Checkbox-class.html',
),
ComponentDemoTabData(
tabName: 'RADIO',
description: _radioText,
demoWidget: buildRadio(),
exampleCodeTag: _radioCode
exampleCodeTag: _radioCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/Radio-class.html',
),
ComponentDemoTabData(
tabName: 'SWITCH',
description: _switchText,
demoWidget: buildSwitch(),
exampleCodeTag: _switchCode
exampleCodeTag: _switchCode,
documentationUrl: 'https://docs.flutter.io/flutter/material/Switch-class.html',
)
];

View File

@ -6,6 +6,8 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class SliderDemo extends StatefulWidget {
static const String routeName = '/material/slider';
@ -132,7 +134,10 @@ class _SliderDemoState extends State<SliderDemo> {
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('Sliders')),
appBar: AppBar(
title: const Text('Sliders'),
actions: <Widget>[MaterialDemoDocumentationButton(SliderDemo.routeName)],
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: Column(

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _text1 =
'Snackbars provide lightweight feedback about an operation by '
'showing a brief message at the bottom of the screen. Snackbars '
@ -73,7 +75,8 @@ class _SnackBarDemoState extends State<SnackBarDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Snackbar')
title: const Text('Snackbar'),
actions: <Widget>[MaterialDemoDocumentationButton(SnackBarDemo.routeName)],
),
body: Builder(
// Create an inner BuildContext so that the snackBar onPressed methods

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
// Each TabBarView contains a _Page and for each _Page there is a list
// of _CardData objects. Each _CardData object is displayed by a _CardItem.
@ -150,6 +152,7 @@ class TabsDemo extends StatelessWidget {
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
child: SliverAppBar(
title: const Text('Tabs and scrolling'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
pinned: true,
expandedHeight: 150.0,
forceElevated: innerBoxIsScrolled,

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _explanatoryText =
"When the Scaffold's floating action button changes, the new button fades and "
'turns into view. In this demo, changing tabs can cause the app to be rebuilt '
@ -137,6 +139,7 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
tabs: _allPages.map((_Page page) => Tab(text: page.label.toUpperCase())).toList(),
),
actions: <Widget>[
MaterialDemoDocumentationButton(TabsFabDemo.routeName),
IconButton(
icon: const Icon(Icons.sentiment_very_satisfied),
onPressed: () {

View File

@ -7,6 +7,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../gallery/demo.dart';
class TextFormFieldDemo extends StatefulWidget {
const TextFormFieldDemo({ Key key }) : super(key: key);
@ -165,6 +167,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Text fields'),
actions: <Widget>[MaterialDemoDocumentationButton(TextFormFieldDemo.routeName)],
),
body: SafeArea(
top: false,

View File

@ -4,6 +4,8 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
const String _introText =
'Tooltips are short identifying messages that briefly appear in response to '
'a long press. Tooltip messages are also used by services that make Flutter '
@ -18,7 +20,8 @@ class TooltipDemo extends StatelessWidget {
final ThemeData theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Tooltips')
title: const Text('Tooltips'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: Builder(
builder: (BuildContext context) {

View File

@ -4,13 +4,18 @@
import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class TwoLevelListDemo extends StatelessWidget {
static const String routeName = '/material/two-level-list';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Expand/collapse list control')),
appBar: AppBar(
title: const Text('Expand/collapse list control'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: ListView(
children: <Widget>[
const ListTile(title: Text('Top')),

View File

@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'demos.dart';
import 'example_code_parser.dart';
import 'syntax_highlighter.dart';
@ -12,24 +15,28 @@ class ComponentDemoTabData {
this.demoWidget,
this.exampleCodeTag,
this.description,
this.tabName
this.tabName,
this.documentationUrl,
});
final Widget demoWidget;
final String exampleCodeTag;
final String description;
final String tabName;
final String documentationUrl;
@override
bool operator==(Object other) {
if (other.runtimeType != runtimeType)
return false;
final ComponentDemoTabData typedOther = other;
return typedOther.tabName == tabName && typedOther.description == description;
return typedOther.tabName == tabName
&& typedOther.description == description
&& typedOther.documentationUrl == documentationUrl;
}
@override
int get hashCode => hashValues(tabName.hashCode, description.hashCode);
int get hashCode => hashValues(tabName, description, documentationUrl);
}
class TabbedComponentDemoScaffold extends StatelessWidget {
@ -52,6 +59,13 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
}
}
void _showApiDocumentation(BuildContext context) {
final String url = demos[DefaultTabController.of(context).index].documentationUrl;
if (url != null) {
launch(url, forceWebView: true);
}
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
@ -61,14 +75,20 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
title: Text(title),
actions: (actions ?? <Widget>[])..addAll(
<Widget>[
Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(Icons.library_books),
onPressed: () => _showApiDocumentation(context),
);
},
),
Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(Icons.code),
tooltip: 'Show example code',
onPressed: () {
_showExampleCode(context);
},
onPressed: () => _showExampleCode(context),
);
},
)
@ -170,3 +190,44 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
);
}
}
class MaterialDemoDocumentationButton extends StatelessWidget {
MaterialDemoDocumentationButton(String routeName, { Key key })
: documentationUrl = kDemoDocumentationUrl[routeName],
assert(
kDemoDocumentationUrl[routeName] != null,
'A documentation URL was not specified for demo route $routeName in kAllGalleryDemos',
),
super(key: key);
final String documentationUrl;
@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.library_books),
onPressed: () => launch(documentationUrl, forceWebView: true)
);
}
}
class CupertinoDemoDocumentationButton extends StatelessWidget {
CupertinoDemoDocumentationButton(String routeName, { Key key })
: documentationUrl = kDemoDocumentationUrl[routeName],
assert(
kDemoDocumentationUrl[routeName] != null,
'A documentation URL was not specified for demo route $routeName in kAllGalleryDemos',
),
super(key: key);
final String documentationUrl;
@override
Widget build(BuildContext context) {
return CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.book),
onPressed: () => launch(documentationUrl, forceWebView: true)
);
}
}

View File

@ -63,6 +63,7 @@ class GalleryDemo {
this.subtitle,
@required this.category,
@required this.routeName,
this.documentationUrl,
@required this.buildRoute,
}) : assert(title != null),
assert(category != null),
@ -75,6 +76,7 @@ class GalleryDemo {
final GalleryDemoCategory category;
final String routeName;
final WidgetBuilder buildRoute;
final String documentationUrl;
@override
String toString() {
@ -143,6 +145,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.bottom_app_bar,
category: _kMaterialComponents,
routeName: BottomAppBarDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/BottomAppBar-class.html',
buildRoute: (BuildContext context) => BottomAppBarDemo(),
),
GalleryDemo(
@ -151,6 +154,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.bottom_navigation,
category: _kMaterialComponents,
routeName: BottomNavigationDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/BottomNavigationBar-class.html',
buildRoute: (BuildContext context) => BottomNavigationDemo(),
),
GalleryDemo(
@ -159,6 +163,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.bottom_sheets,
category: _kMaterialComponents,
routeName: ModalBottomSheetDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/showModalBottomSheet.html',
buildRoute: (BuildContext context) => ModalBottomSheetDemo(),
),
GalleryDemo(
@ -167,6 +172,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.bottom_sheet_persistent,
category: _kMaterialComponents,
routeName: PersistentBottomSheetDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ScaffoldState/showBottomSheet.html',
buildRoute: (BuildContext context) => PersistentBottomSheetDemo(),
),
GalleryDemo(
@ -183,6 +189,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.buttons,
category: _kMaterialComponents,
routeName: TabsFabDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/FloatingActionButton-class.html',
buildRoute: (BuildContext context) => TabsFabDemo(),
),
GalleryDemo(
@ -191,6 +198,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.cards,
category: _kMaterialComponents,
routeName: CardsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Card-class.html',
buildRoute: (BuildContext context) => CardsDemo(),
),
GalleryDemo(
@ -199,6 +207,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.chips,
category: _kMaterialComponents,
routeName: ChipDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Chip-class.html',
buildRoute: (BuildContext context) => ChipDemo(),
),
GalleryDemo(
@ -207,6 +216,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.data_table,
category: _kMaterialComponents,
routeName: DataTableDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/PaginatedDataTable-class.html',
buildRoute: (BuildContext context) => DataTableDemo(),
),
GalleryDemo(
@ -215,6 +225,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.dialogs,
category: _kMaterialComponents,
routeName: DialogDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/showDialog.html',
buildRoute: (BuildContext context) => DialogDemo(),
),
GalleryDemo(
@ -224,6 +235,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.cupertino_progress,
category: _kMaterialComponents,
routeName: ElevationDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Material/elevation.html',
buildRoute: (BuildContext context) => ElevationDemo(),
),
GalleryDemo(
@ -232,6 +244,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.expand_all,
category: _kMaterialComponents,
routeName: TwoLevelListDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ExpansionTile-class.html',
buildRoute: (BuildContext context) => TwoLevelListDemo(),
),
GalleryDemo(
@ -240,6 +253,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.expand_all,
category: _kMaterialComponents,
routeName: ExpansionPanelsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ExpansionPanel-class.html',
buildRoute: (BuildContext context) => ExpansionPanelsDemo(),
),
GalleryDemo(
@ -248,6 +262,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.grid_on,
category: _kMaterialComponents,
routeName: GridListDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/widgets/GridView-class.html',
buildRoute: (BuildContext context) => const GridListDemo(),
),
GalleryDemo(
@ -256,6 +271,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.sentiment_very_satisfied,
category: _kMaterialComponents,
routeName: IconsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/IconButton-class.html',
buildRoute: (BuildContext context) => IconsDemo(),
),
GalleryDemo(
@ -264,6 +280,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.list_alt,
category: _kMaterialComponents,
routeName: ListDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ListTile-class.html',
buildRoute: (BuildContext context) => const ListDemo(),
),
GalleryDemo(
@ -272,6 +289,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.lists_leave_behind,
category: _kMaterialComponents,
routeName: LeaveBehindDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/widgets/Dismissible-class.html',
buildRoute: (BuildContext context) => const LeaveBehindDemo(),
),
GalleryDemo(
@ -280,6 +298,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.list_alt,
category: _kMaterialComponents,
routeName: ReorderableListDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ReorderableListView-class.html',
buildRoute: (BuildContext context) => const ReorderableListDemo(),
),
GalleryDemo(
@ -288,6 +307,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.more_vert,
category: _kMaterialComponents,
routeName: MenuDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/PopupMenuButton-class.html',
buildRoute: (BuildContext context) => const MenuDemo(),
),
GalleryDemo(
@ -296,6 +316,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.menu,
category: _kMaterialComponents,
routeName: DrawerDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Drawer-class.html',
buildRoute: (BuildContext context) => DrawerDemo(),
),
GalleryDemo(
@ -304,6 +325,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.page_control,
category: _kMaterialComponents,
routeName: PageSelectorDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/TabBarView-class.html',
buildRoute: (BuildContext context) => PageSelectorDemo(),
),
GalleryDemo(
@ -312,6 +334,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.event,
category: _kMaterialComponents,
routeName: DateAndTimePickerDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/showDatePicker.html',
buildRoute: (BuildContext context) => DateAndTimePickerDemo(),
),
GalleryDemo(
@ -320,6 +343,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.progress_activity,
category: _kMaterialComponents,
routeName: ProgressIndicatorDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/LinearProgressIndicator-class.html',
buildRoute: (BuildContext context) => ProgressIndicatorDemo(),
),
GalleryDemo(
@ -328,6 +352,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.refresh,
category: _kMaterialComponents,
routeName: OverscrollDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/RefreshIndicator-class.html',
buildRoute: (BuildContext context) => const OverscrollDemo(),
),
GalleryDemo(
@ -336,6 +361,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: Icons.search,
category: _kMaterialComponents,
routeName: SearchDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/showSearch.html',
buildRoute: (BuildContext context) => SearchDemo(),
),
GalleryDemo(
@ -352,6 +378,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.sliders,
category: _kMaterialComponents,
routeName: SliderDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Slider-class.html',
buildRoute: (BuildContext context) => SliderDemo(),
),
GalleryDemo(
@ -360,6 +387,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.snackbar,
category: _kMaterialComponents,
routeName: SnackBarDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/ScaffoldState/showSnackBar.html',
buildRoute: (BuildContext context) => const SnackBarDemo(),
),
GalleryDemo(
@ -368,6 +396,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.tabs,
category: _kMaterialComponents,
routeName: TabsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/TabBarView-class.html',
buildRoute: (BuildContext context) => TabsDemo(),
),
GalleryDemo(
@ -376,6 +405,7 @@ List<GalleryDemo> _buildGalleryDemos() {
category: _kMaterialComponents,
icon: GalleryIcons.tabs,
routeName: ScrollableTabsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/TabBar-class.html',
buildRoute: (BuildContext context) => ScrollableTabsDemo(),
),
GalleryDemo(
@ -384,6 +414,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.text_fields_alt,
category: _kMaterialComponents,
routeName: TextFormFieldDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/TextFormField-class.html',
buildRoute: (BuildContext context) => const TextFormFieldDemo(),
),
GalleryDemo(
@ -392,6 +423,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.tooltip,
category: _kMaterialComponents,
routeName: TooltipDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/material/Tooltip-class.html',
buildRoute: (BuildContext context) => TooltipDemo(),
),
@ -401,6 +433,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.cupertino_progress,
category: _kCupertinoComponents,
routeName: CupertinoProgressIndicatorDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoActivityIndicator-class.html',
buildRoute: (BuildContext context) => CupertinoProgressIndicatorDemo(),
),
GalleryDemo(
@ -408,6 +441,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.dialogs,
category: _kCupertinoComponents,
routeName: CupertinoAlertDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/showCupertinoDialog.html',
buildRoute: (BuildContext context) => CupertinoAlertDemo(),
),
GalleryDemo(
@ -415,6 +449,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.generic_buttons,
category: _kCupertinoComponents,
routeName: CupertinoButtonsDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoButton-class.html',
buildRoute: (BuildContext context) => CupertinoButtonsDemo(),
),
GalleryDemo(
@ -422,6 +457,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.bottom_navigation,
category: _kCupertinoComponents,
routeName: CupertinoNavigationDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoTabScaffold-class.html',
buildRoute: (BuildContext context) => CupertinoNavigationDemo(),
),
GalleryDemo(
@ -429,6 +465,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.event,
category: _kCupertinoComponents,
routeName: CupertinoPickerDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoPicker-class.html',
buildRoute: (BuildContext context) => CupertinoPickerDemo(),
),
GalleryDemo(
@ -436,6 +473,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.cupertino_pull_to_refresh,
category: _kCupertinoComponents,
routeName: CupertinoRefreshControlDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoSliverRefreshControl-class.html',
buildRoute: (BuildContext context) => CupertinoRefreshControlDemo(),
),
GalleryDemo(
@ -443,6 +481,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.tabs,
category: _kCupertinoComponents,
routeName: CupertinoSegmentedControlDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoSegmentedControl-class.html',
buildRoute: (BuildContext context) => CupertinoSegmentedControlDemo(),
),
GalleryDemo(
@ -450,6 +489,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.sliders,
category: _kCupertinoComponents,
routeName: CupertinoSliderDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoSlider-class.html',
buildRoute: (BuildContext context) => CupertinoSliderDemo(),
),
GalleryDemo(
@ -457,6 +497,7 @@ List<GalleryDemo> _buildGalleryDemos() {
icon: GalleryIcons.cupertino_switch,
category: _kCupertinoComponents,
routeName: CupertinoSwitchDemo.routeName,
documentationUrl: 'https://docs.flutter.io/flutter/cupertino/CupertinoSwitch-class.html',
buildRoute: (BuildContext context) => CupertinoSwitchDemo(),
),
@ -510,3 +551,10 @@ final Map<GalleryDemoCategory, List<GalleryDemo>> kGalleryCategoryToDemos =
return kAllGalleryDemos.where((GalleryDemo demo) => demo.category == category).toList();
},
);
final Map<String, String> kDemoDocumentationUrl =
Map<String, String>.fromIterable(
kAllGalleryDemos.where((GalleryDemo demo) => demo.documentationUrl != null),
key: (dynamic demo) => demo.routeName,
value: (dynamic demo) => demo.documentationUrl,
);