gallery_page.dart 2.56 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

7
import 'demo/widget_demo.dart';
8

9
class GalleryPage extends StatefulComponent {
10
  GalleryPage({ this.demos, this.active, this.onThemeChanged });
11

12 13
  final List<WidgetDemo> demos;
  final WidgetDemo active;
14
  final ValueChanged<ThemeData> onThemeChanged;
15

16 17 18 19 20
  _GalleryPageState createState() => new _GalleryPageState();
}

class _GalleryPageState extends State<GalleryPage> {
  Widget _buildDrawer() {
21
    List<Widget> items = <Widget>[
22
      new DrawerHeader(child: new Text('Flutter Material demos')),
23 24
    ];

25
    for (WidgetDemo demo in config.demos) {
26 27
      items.add(new DrawerItem(
        onPressed: () {
Hixie's avatar
Hixie committed
28
          Navigator.pushNamed(context, demo.routeName);
29 30 31 32 33
        },
        child: new Text(demo.title)
      ));
    }

34 35
    // TODO(eseidel): We should make this into a shared DrawerFooter.
    items.add(new DrawerDivider());
36 37 38 39 40 41 42 43 44 45
    items.add(new DrawerItem(child: new Flex(
      children: <Widget>[
        new Text("Made with Flutter "),
        new Container(
          margin: const EdgeDims.symmetric(horizontal: 5.0),
          child: new AssetImage(
              name: 'assets/flutter_logo.png',
              height: 16.0,
              fit: ImageFit.contain
          )
46
        )
47 48
      ]
    )));
49

50
    return new Drawer(child: new Block(items));
51 52
  }

53 54 55
  Widget _buildBody() {
    if (config.active != null)
      return config.active.builder(context);
56 57 58 59 60 61
    return new Material(
      child: new Center(
        child: new Text('Select a demo from the drawer')
      )
    );
  }
62

63 64
  Widget _buildTabBar() {
    final WidgetBuilder builder = config.active?.tabBarBuilder;
65 66 67
    return builder != null ? builder(context) : null;
  }

68 69 70 71 72
  Widget _buildPageWrapper(BuildContext context, Widget child) {
    final PageWrapperBuilder builder = config.active?.pageWrapperBuilder;
    return builder != null ? builder(context, child) : child;
  }

73 74 75 76 77
  Widget _buildFloatingActionButton() {
    final WidgetBuilder builder = config.active?.floatingActionButtonBuilder;
    return builder != null ? builder(context) : null;
  }

78
  Widget build(BuildContext context) {
79 80 81 82 83 84 85 86 87 88
    return _buildPageWrapper(context,
      new Scaffold(
        toolBar: new ToolBar(
          center: new Text(config.active?.title ?? 'Flutter Material gallery'),
          tabBar: _buildTabBar()
        ),
        drawer: _buildDrawer(),
        floatingActionButton: _buildFloatingActionButton(),
        body: _buildBody()
      )
89 90 91
    );
  }
}