stock_menu.dart 3.01 KB
Newer Older
1 2 3 4
// 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.

5
part of stocks;
6

7
enum _MenuItems { autorefresh, autorefreshCheckbox, refresh, speedUp, speedDown }
8

Hans Muller's avatar
Hans Muller committed
9 10
const double _kMenuMargin = 16.0; // 24.0 on tablet

Hixie's avatar
Hixie committed
11
Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool> onAutorefreshChanged }) async {
12
  StateSetter autorefreshStateSetter;
13
  switch (await showMenu(
Adam Barth's avatar
Adam Barth committed
14
    context: context,
15
    position: new ModalPosition(
16 17
      right: ui.window.padding.right + _kMenuMargin,
      top: ui.window.padding.top + _kMenuMargin
18
    ),
Adam Barth's avatar
Adam Barth committed
19 20 21 22 23
    items: <PopupMenuItem>[
      new PopupMenuItem(
        value: _MenuItems.autorefresh,
        child: new Row(<Widget>[
            new Flexible(child: new Text('Autorefresh')),
24 25 26 27 28 29 30 31 32 33 34 35
            new StatefulBuilder(
              builder: (BuildContext context, StateSetter setState) {
                autorefreshStateSetter = setState;
                return new Checkbox(
                  value: autorefresh,
                  onChanged: (bool value) {
                    setState(() {
                      autorefresh = value;
                    });
                    Navigator.pop(context, _MenuItems.autorefreshCheckbox);
                  }
                );
Adam Barth's avatar
Adam Barth committed
36 37 38 39 40 41
              }
            )
          ]
        )
      ),
      new PopupMenuItem(
42 43
        value: _MenuItems.refresh,
        child: new Text('Refresh')
Adam Barth's avatar
Adam Barth committed
44 45
      ),
      new PopupMenuItem(
46 47 48 49 50 51
        value: _MenuItems.speedUp,
        child: new Text('Increase animation speed')
      ),
      new PopupMenuItem(
        value: _MenuItems.speedDown,
        child: new Text('Decrease animation speed')
Adam Barth's avatar
Adam Barth committed
52 53
      ),
    ]
54 55
  )) {
    case _MenuItems.autorefresh:
56 57 58
      autorefreshStateSetter(() {
        autorefresh = !autorefresh;
      });
59 60 61 62
      continue autorefreshNotify;
    autorefreshNotify:
    case _MenuItems.autorefreshCheckbox:
      onAutorefreshChanged(autorefresh);
63
      break;
64 65 66 67 68 69 70
    case _MenuItems.speedUp:
      timeDilation /= 5.0;
      break;
    case _MenuItems.speedDown:
      timeDilation *= 5.0;
      break;
    case _MenuItems.refresh:
Adam Barth's avatar
Adam Barth committed
71 72 73
      await showDialog(
        context: context,
        child: new Dialog(
74 75
          title: new Text('Not Implemented'),
          content: new Text('This feature has not yet been implemented.'),
Hixie's avatar
Hixie committed
76
          actions: <Widget>[
77
            new FlatButton(
Hixie's avatar
Hixie committed
78
              child: new Row(<Widget>[
79
                new Icon(
80
                  icon: 'device/dvr',
81
                  size: IconSize.s18
82 83 84 85 86 87 88 89
                ),
                new Container(
                  width: 8.0
                ),
                new Text('DUMP APP TO CONSOLE'),
              ]),
              onPressed: () { debugDumpApp(); }
            ),
90 91 92
            new FlatButton(
              child: new Text('OH WELL'),
              onPressed: () {
Hixie's avatar
Hixie committed
93
                Navigator.pop(context, false);
94 95 96
              }
            ),
          ]
Adam Barth's avatar
Adam Barth committed
97 98
        )
      );
99 100 101 102
      break;
    default:
      // menu was canceled.
  }
Adam Barth's avatar
Adam Barth committed
103
}