stock_settings.dart 7.51 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(widget.configuration.copyWith(stockMode: value ? StockMode.optimistic : StockMode.pessimistic));
23 24 25
  }

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

  void _handleShowGridChanged(bool value) {
30
    sendUpdates(widget.configuration.copyWith(debugShowGrid: value));
31 32 33
  }

  void _handleShowSizesChanged(bool value) {
34
    sendUpdates(widget.configuration.copyWith(debugShowSizes: value));
35 36
  }

37
  void _handleShowBaselinesChanged(bool value) {
38
    sendUpdates(widget.configuration.copyWith(debugShowBaselines: value));
39 40 41
  }

  void _handleShowLayersChanged(bool value) {
42
    sendUpdates(widget.configuration.copyWith(debugShowLayers: value));
43 44 45
  }

  void _handleShowPointersChanged(bool value) {
46
    sendUpdates(widget.configuration.copyWith(debugShowPointers: value));
47 48 49
  }

  void _handleShowRainbowChanged(bool value) {
50
    sendUpdates(widget.configuration.copyWith(debugShowRainbow: value));
51 52 53
  }


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

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

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

95
  void sendUpdates(StockConfiguration value) {
96 97
    if (widget.updater != null)
      widget.updater(value);
98 99
  }

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

106
  Widget buildSettingsPane(BuildContext context) {
107
    final List<Widget> rows = <Widget>[
108
      new ListTile(
109 110
        leading: const Icon(Icons.thumb_up),
        title: const Text('Everything is awesome'),
111 112
        onTap: _confirmOptimismChange,
        trailing: new Checkbox(
113
          value: widget.configuration.stockMode == StockMode.optimistic,
114 115
          onChanged: (bool value) => _confirmOptimismChange(),
        ),
Ian Hickson's avatar
Ian Hickson committed
116
      ),
117
      new ListTile(
118 119
        leading: const Icon(Icons.backup),
        title: const Text('Back up stock list to the cloud'),
120
        onTap: () { _handleBackupChanged(!(widget.configuration.backupMode == BackupMode.enabled)); },
121
        trailing: new Switch(
122
          value: widget.configuration.backupMode == BackupMode.enabled,
123 124
          onChanged: _handleBackupChanged,
        ),
Ian Hickson's avatar
Ian Hickson committed
125
      ),
126
      new ListTile(
127 128
        leading: const Icon(Icons.picture_in_picture),
        title: const Text('Show rendering performance overlay'),
129
        onTap: () { _handleShowPerformanceOverlayChanged(!widget.configuration.showPerformanceOverlay); },
130
        trailing: new Switch(
131
          value: widget.configuration.showPerformanceOverlay,
132 133
          onChanged: _handleShowPerformanceOverlayChanged,
        ),
134
      ),
135
      new ListTile(
136 137
        leading: const Icon(Icons.accessibility),
        title: const Text('Show semantics overlay'),
138
        onTap: () { _handleShowSemanticsDebuggerChanged(!widget.configuration.showSemanticsDebugger); },
139
        trailing: new Switch(
140
          value: widget.configuration.showSemanticsDebugger,
141 142
          onChanged: _handleShowSemanticsDebuggerChanged,
        ),
Hixie's avatar
Hixie committed
143
      ),
Ian Hickson's avatar
Ian Hickson committed
144 145
    ];
    assert(() {
146
      // material grid and size construction lines are only available in checked mode
Ian Hickson's avatar
Ian Hickson committed
147
      rows.addAll(<Widget>[
148
        new ListTile(
149 150
          leading: const Icon(Icons.border_clear),
          title: const Text('Show material grid (for debugging)'),
151
          onTap: () { _handleShowGridChanged(!widget.configuration.debugShowGrid); },
152
          trailing: new Switch(
153
            value: widget.configuration.debugShowGrid,
154 155
            onChanged: _handleShowGridChanged,
          ),
156
        ),
157
        new ListTile(
158 159
          leading: const Icon(Icons.border_all),
          title: const Text('Show construction lines (for debugging)'),
160
          onTap: () { _handleShowSizesChanged(!widget.configuration.debugShowSizes); },
161
          trailing: new Switch(
162
            value: widget.configuration.debugShowSizes,
163 164
            onChanged: _handleShowSizesChanged,
          ),
165
        ),
166
        new ListTile(
167 168
          leading: const Icon(Icons.format_color_text),
          title: const Text('Show baselines (for debugging)'),
169
          onTap: () { _handleShowBaselinesChanged(!widget.configuration.debugShowBaselines); },
170
          trailing: new Switch(
171
            value: widget.configuration.debugShowBaselines,
172 173
            onChanged: _handleShowBaselinesChanged,
          ),
174
        ),
175
        new ListTile(
176 177
          leading: const Icon(Icons.filter_none),
          title: const Text('Show layer boundaries (for debugging)'),
178
          onTap: () { _handleShowLayersChanged(!widget.configuration.debugShowLayers); },
179
          trailing: new Switch(
180
            value: widget.configuration.debugShowLayers,
181 182
            onChanged: _handleShowLayersChanged,
          ),
183
        ),
184
        new ListTile(
185 186
          leading: const Icon(Icons.mouse),
          title: const Text('Show pointer hit-testing (for debugging)'),
187
          onTap: () { _handleShowPointersChanged(!widget.configuration.debugShowPointers); },
188
          trailing: new Switch(
189
            value: widget.configuration.debugShowPointers,
190 191
            onChanged: _handleShowPointersChanged,
          ),
192
        ),
193
        new ListTile(
194 195
          leading: const Icon(Icons.gradient),
          title: const Text('Show repaint rainbow (for debugging)'),
196
          onTap: () { _handleShowRainbowChanged(!widget.configuration.debugShowRainbow); },
197
          trailing: new Switch(
198
            value: widget.configuration.debugShowRainbow,
199 200
            onChanged: _handleShowRainbowChanged,
          ),
201
        ),
202
      ]);
Ian Hickson's avatar
Ian Hickson committed
203
      return true;
204
    }());
205
    return new ListView(
206
      padding: const EdgeInsets.symmetric(vertical: 20.0),
207
      children: rows,
208 209 210
    );
  }

211
  @override
212
  Widget build(BuildContext context) {
213
    return new Scaffold(
214
      appBar: buildAppBar(context),
215
      body: buildSettingsPane(context)
216
    );
217 218
  }
}