scrolling_techniques_demo.dart 4.43 KB
Newer Older
1 2 3 4 5 6 7 8
// 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 'flexible_space_demo.dart';

9
class _BarGraphic extends StatelessWidget {
10 11 12 13 14 15 16 17 18 19 20 21
  _BarGraphic({ Key key, this.height, this.color, this.leftText, this.rightText: '' })
    : super(key: key) {
    assert(height != null);
    assert(color != null);
    assert(leftText != null);
  }

  final double height;
  final Color color;
  final String leftText;
  final String rightText;

22
  @override
23 24 25 26
  Widget build(BuildContext context) {
    return new Container(
      height: height,
      width: 200.0,
27
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
28 29
      decoration: new BoxDecoration(backgroundColor: color),
      child: new DefaultTextStyle(
30
        style: Theme.of(context).textTheme.body1.copyWith(color: Colors.white),
31
        child: new Row(
32
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
          children: <Widget>[
            new Text(leftText),
            new Text(rightText)
          ]
        )
      )
    );
  }
}

class _StatusBarGraphic extends _BarGraphic {
  _StatusBarGraphic() : super(
    height: 24.0,
    color: Colors.green[400],
    leftText: 'Status Bar',
    rightText: '24dp'
  );
}

52 53
class _AppBarGraphic extends _BarGraphic {
  _AppBarGraphic() : super(
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    height: 48.0,
    color: Colors.blue[400],
    leftText: 'Tool Bar',
    rightText: '48dp'
  );
}

class _TabBarGraphic extends _BarGraphic {
  _TabBarGraphic() : super(
    height: 48.0,
    color: Colors.purple[400],
    leftText: 'Tab Bar',
    rightText: '56dp'
  );
}

class _FlexibleSpaceGraphic extends _BarGraphic {
  _FlexibleSpaceGraphic() : super(
    height: 128.0,
    color: Colors.pink[400],
    leftText: 'Flexible Space'
  );
}

78
class _TechniqueItem extends StatelessWidget {
79 80 81 82 83 84 85
  _TechniqueItem({ this.titleText, this.barGraphics, this.builder });

  final String titleText;
  final List<Widget> barGraphics;
  final WidgetBuilder builder;

  void showDemo(BuildContext context) {
86
    Navigator.push(context, new MaterialPageRoute<Null>(builder: builder));
87 88
  }

89
  @override
90 91 92 93 94
  Widget build(BuildContext context) {
    return new Card(
      child: new InkWell(
        onTap: () { showDemo(context); },
        child: new Padding(
95
          padding: const EdgeInsets.all(16.0),
96
          child: new Row(
97
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
            children :<Widget>[
              new Text(titleText),
              new Column(children: barGraphics)
            ]
          )
        )
      )
    );
  }
}

const String _introText =
  "An AppBar is a combination of a ToolBar and a TabBar or a flexible space "
  "Widget that is managed by the Scaffold. The Scaffold pads the ToolBar so that "
  "it appears behind the device's status bar. When a flexible space Widget is "
  "specified it is stacked on top of the ToolBar.";

115
class ScrollingTechniquesDemo extends StatelessWidget {
116
  @override
117 118
  Widget build(BuildContext context) {
    return new Scaffold(
119
      appBar: new AppBar(title: new Text('Scrolling techniques')),
120
      body: new Padding(
121
        padding: const EdgeInsets.symmetric(horizontal: 16.0),
122 123 124
        child: new Block(
          children: <Widget>[
            new Padding(
125
              padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 32.0),
126
              child: new Text(_introText, style: Theme.of(context).textTheme.caption)
127 128 129 130 131 132
            ),
            new _TechniqueItem(
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              titleText: 'Standard',
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
133
                new _AppBarGraphic()
134 135 136 137 138 139 140
              ]
            ),
            new _TechniqueItem(
              titleText: 'Tabs',
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
141
                new _AppBarGraphic(),
142 143 144 145 146 147 148 149
                new _TabBarGraphic()
              ]
            ),
            new _TechniqueItem(
              titleText: 'Flexible',
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
150
                new _AppBarGraphic(),
151 152 153 154 155 156 157 158 159
                new _FlexibleSpaceGraphic()
              ]
            )
          ]
        )
      )
    );
  }
}