stock_settings.dart 8.28 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 6 7
import 'package:flutter/material.dart';

import 'stock_types.dart';
8

9
class StockSettings extends StatefulWidget {
10
  const StockSettings(this.configuration, this.updater);
11

12 13
  final StockConfiguration configuration;
  final ValueChanged<StockConfiguration> updater;
14

15
  @override
16 17
  StockSettingsState createState() => new StockSettingsState();
}
18

19
class StockSettingsState extends State<StockSettings> {
20
  void _handleOptimismChanged(bool value) {
21
    value ??= false;
22
    sendUpdates(config.configuration.copyWith(stockMode: value ? StockMode.optimistic : StockMode.pessimistic));
23 24 25
  }

  void _handleBackupChanged(bool value) {
26
    sendUpdates(config.configuration.copyWith(backupMode: value ? BackupMode.enabled : BackupMode.disabled));
Ian Hickson's avatar
Ian Hickson committed
27 28 29
  }

  void _handleShowGridChanged(bool value) {
30 31 32 33 34 35 36
    sendUpdates(config.configuration.copyWith(debugShowGrid: value));
  }

  void _handleShowSizesChanged(bool value) {
    sendUpdates(config.configuration.copyWith(debugShowSizes: value));
  }

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  void _handleShowBaselinesChanged(bool value) {
    sendUpdates(config.configuration.copyWith(debugShowBaselines: value));
  }

  void _handleShowLayersChanged(bool value) {
    sendUpdates(config.configuration.copyWith(debugShowLayers: value));
  }

  void _handleShowPointersChanged(bool value) {
    sendUpdates(config.configuration.copyWith(debugShowPointers: value));
  }

  void _handleShowRainbowChanged(bool value) {
    sendUpdates(config.configuration.copyWith(debugShowRainbow: value));
  }


54 55
  void _handleShowPerformanceOverlayChanged(bool value) {
    sendUpdates(config.configuration.copyWith(showPerformanceOverlay: value));
56 57
  }

Hixie's avatar
Hixie committed
58 59 60 61
  void _handleShowSemanticsDebuggerChanged(bool value) {
    sendUpdates(config.configuration.copyWith(showSemanticsDebugger: value));
  }

Adam Barth's avatar
Adam Barth committed
62
  void _confirmOptimismChange() {
63
    switch (config.configuration.stockMode) {
64 65 66 67
      case StockMode.optimistic:
        _handleOptimismChanged(false);
        break;
      case StockMode.pessimistic:
Adam Barth's avatar
Adam Barth committed
68 69 70
        showDialog(
          context: context,
          child: new Dialog(
71 72
            title: new Text("Change mode?"),
            content: new Text("Optimistic mode means everything is awesome. Are you sure you can handle that?"),
Hixie's avatar
Hixie committed
73
            actions: <Widget>[
74 75
              new FlatButton(
                child: new Text('NO THANKS'),
76
                onPressed: () {
Hixie's avatar
Hixie committed
77
                  Navigator.pop(context, false);
78
                }
79 80 81 82
              ),
              new FlatButton(
                child: new Text('AGREE'),
                onPressed: () {
Hixie's avatar
Hixie committed
83
                  Navigator.pop(context, true);
84 85 86
                }
              ),
            ]
Adam Barth's avatar
Adam Barth committed
87 88
          )
        ).then(_handleOptimismChanged);
89 90 91 92
        break;
    }
  }

93
  void sendUpdates(StockConfiguration value) {
94
    if (config.updater != null)
95
      config.updater(value);
96 97
  }

98 99 100
  Widget buildAppBar(BuildContext context) {
    return new AppBar(
      title: new Text('Settings')
101 102 103
    );
  }

104
  Widget buildSettingsPane(BuildContext context) {
Ian Hickson's avatar
Ian Hickson committed
105 106
    List<Widget> rows = <Widget>[
      new DrawerItem(
107
        icon: Icons.thumb_up,
Ian Hickson's avatar
Ian Hickson committed
108
        onPressed: () => _confirmOptimismChange(),
109 110 111 112 113 114 115 116 117
        child: new Row(
          children: <Widget>[
            new Flexible(child: new Text('Everything is awesome')),
            new Checkbox(
              value: config.configuration.stockMode == StockMode.optimistic,
              onChanged: (bool value) => _confirmOptimismChange()
            ),
          ]
        )
Ian Hickson's avatar
Ian Hickson committed
118 119
      ),
      new DrawerItem(
120
        icon: Icons.backup,
121
        onPressed: () { _handleBackupChanged(!(config.configuration.backupMode == BackupMode.enabled)); },
122 123 124 125 126 127 128 129 130
        child: new Row(
          children: <Widget>[
            new Flexible(child: new Text('Back up stock list to the cloud')),
            new Switch(
              value: config.configuration.backupMode == BackupMode.enabled,
              onChanged: _handleBackupChanged
            ),
          ]
        )
Ian Hickson's avatar
Ian Hickson committed
131
      ),
132
      new DrawerItem(
133
        icon: Icons.picture_in_picture,
134
        onPressed: () { _handleShowPerformanceOverlayChanged(!config.configuration.showPerformanceOverlay); },
135 136 137 138 139 140 141 142 143
        child: new Row(
          children: <Widget>[
            new Flexible(child: new Text('Show rendering performance overlay')),
            new Switch(
              value: config.configuration.showPerformanceOverlay,
              onChanged: _handleShowPerformanceOverlayChanged
            ),
          ]
        )
144
      ),
Hixie's avatar
Hixie committed
145
      new DrawerItem(
146
        icon: Icons.accessibility,
Hixie's avatar
Hixie committed
147 148 149 150 151 152 153 154 155 156 157
        onPressed: () { _handleShowSemanticsDebuggerChanged(!config.configuration.showSemanticsDebugger); },
        child: new Row(
          children: <Widget>[
            new Flexible(child: new Text('Show semantics overlay')),
            new Switch(
              value: config.configuration.showSemanticsDebugger,
              onChanged: _handleShowSemanticsDebuggerChanged
            ),
          ]
        )
      ),
Ian Hickson's avatar
Ian Hickson committed
158 159
    ];
    assert(() {
160 161
      // material grid and size construction lines are only available in checked mode
      rows.addAll([
Hixie's avatar
Hixie committed
162
        new DrawerItem(
163
          icon: Icons.border_clear,
164
          onPressed: () { _handleShowGridChanged(!config.configuration.debugShowGrid); },
165 166 167 168 169 170 171 172 173
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show material grid (for debugging)')),
              new Switch(
                value: config.configuration.debugShowGrid,
                onChanged: _handleShowGridChanged
              ),
            ]
          )
174 175
        ),
        new DrawerItem(
176
          icon: Icons.border_all,
177
          onPressed: () { _handleShowSizesChanged(!config.configuration.debugShowSizes); },
178 179 180 181 182 183 184 185 186
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show construction lines (for debugging)')),
              new Switch(
                value: config.configuration.debugShowSizes,
                onChanged: _handleShowSizesChanged
              ),
            ]
          )
187 188
        ),
        new DrawerItem(
189
          icon: Icons.format_color_text,
190 191 192 193 194 195 196 197 198 199 200 201
          onPressed: () { _handleShowBaselinesChanged(!config.configuration.debugShowBaselines); },
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show baselines (for debugging)')),
              new Switch(
                value: config.configuration.debugShowBaselines,
                onChanged: _handleShowBaselinesChanged
              ),
            ]
          )
        ),
        new DrawerItem(
202
          icon: Icons.filter_none,
203 204 205 206 207 208 209 210 211 212 213 214
          onPressed: () { _handleShowLayersChanged(!config.configuration.debugShowLayers); },
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show layer boundaries (for debugging)')),
              new Switch(
                value: config.configuration.debugShowLayers,
                onChanged: _handleShowLayersChanged
              ),
            ]
          )
        ),
        new DrawerItem(
215
          icon: Icons.mouse,
216 217 218 219 220 221 222 223 224 225 226 227
          onPressed: () { _handleShowPointersChanged(!config.configuration.debugShowPointers); },
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show pointer hit-testing (for debugging)')),
              new Switch(
                value: config.configuration.debugShowPointers,
                onChanged: _handleShowPointersChanged
              ),
            ]
          )
        ),
        new DrawerItem(
228
          icon: Icons.gradient,
229 230 231 232 233 234 235 236 237 238 239
          onPressed: () { _handleShowRainbowChanged(!config.configuration.debugShowRainbow); },
          child: new Row(
            children: <Widget>[
              new Flexible(child: new Text('Show repaint rainbow (for debugging)')),
              new Switch(
                value: config.configuration.debugShowRainbow,
                onChanged: _handleShowRainbowChanged
              ),
            ]
          )
        ),
240
      ]);
Ian Hickson's avatar
Ian Hickson committed
241 242 243
      return true;
    });
    return new Block(
244
      children: rows,
245
      padding: const EdgeInsets.symmetric(vertical: 20.0)
246 247 248
    );
  }

249
  @override
250
  Widget build(BuildContext context) {
251
    return new Scaffold(
252
      appBar: buildAppBar(context),
253
      body: buildSettingsPane(context)
254
    );
255 256
  }
}