scrolling_techniques_demo.dart 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
// 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';

class _BarGraphic extends StatelessComponent {
  _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;

  Widget build(BuildContext context) {
    return new Container(
      height: height,
      width: 200.0,
      padding: const EdgeDims.symmetric(horizontal: 16.0),
      decoration: new BoxDecoration(backgroundColor: color),
      child: new DefaultTextStyle(
        style: Theme.of(context).text.body1.copyWith(color: Colors.white),
        child: new Row(
          justifyContent: FlexJustifyContent.spaceBetween,
          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'
  );
}

class _ToolBarGraphic extends _BarGraphic {
  _ToolBarGraphic() : super(
    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'
  );
}

class _TechniqueItem extends StatelessComponent {
  _TechniqueItem({ this.titleText, this.barGraphics, this.builder });

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

  void showDemo(BuildContext context) {
    Navigator.push(context, new MaterialPageRoute(builder: builder));
  }

  Widget build(BuildContext context) {
    return new Card(
      child: new InkWell(
        onTap: () { showDemo(context); },
        child: new Padding(
          padding: const EdgeDims.all(16.0),
          child: new Row(
            justifyContent: FlexJustifyContent.spaceBetween,
            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.";

class ScrollingTechniquesDemo extends StatelessComponent {
  Widget build(BuildContext context) {
    return new Scaffold(
      toolBar: new ToolBar(center: new Text('Scrolling Techniques')),
      body: new Padding(
        padding: const EdgeDims.symmetric(horizontal: 16.0),
        child: new Block(
          children: <Widget>[
            new Padding(
              padding: const EdgeDims.symmetric(horizontal: 16.0, vertical: 32.0),
              child: new Text(_introText, style: Theme.of(context).text.caption)
            ),
            new _TechniqueItem(
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              titleText: 'Standard',
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
                new _ToolBarGraphic()
              ]
            ),
            new _TechniqueItem(
              titleText: 'Tabs',
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
                new _ToolBarGraphic(),
                new _TabBarGraphic()
              ]
            ),
            new _TechniqueItem(
              titleText: 'Flexible',
              builder: (BuildContext context) => new FlexibleSpaceDemo(),
              barGraphics: <Widget>[
                new _StatusBarGraphic(),
                new _ToolBarGraphic(),
                new _FlexibleSpaceGraphic()
              ]
            )
          ]
        )
      )
    );
  }
}