Improve Material selection controls

- These controls now have proper radial reactions.
 - You can drag the switch.
 - The radio button animates properly.
 - There's a demo in the Material Gallery
This commit is contained in:
Adam Barth
2015-11-26 01:14:41 -08:00
parent 5873905e5a
commit 3f06da0eaa
9 changed files with 386 additions and 252 deletions

View File

@@ -0,0 +1,64 @@
// 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.
import 'package:flutter/material.dart';
import 'widget_demo.dart';
class SelectionControlsDemo extends StatefulComponent {
_SelectionControlsDemoState createState() => new _SelectionControlsDemoState();
}
class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
bool _checkboxValue = false;
int _radioValue = 0;
bool _switchValue = false;
void _setCheckboxValue(bool value) {
setState(() {
_checkboxValue = value;
});
}
void _setRadioValue(int value) {
setState(() {
_radioValue = value;
});
}
void _setSwitchValue(bool value) {
setState(() {
_switchValue = value;
});
}
Widget build(BuildContext context) {
return new Column([
new Row([
new Checkbox(value: _checkboxValue, onChanged: _setCheckboxValue),
new Checkbox(value: false), // Disabled
], justifyContent: FlexJustifyContent.spaceAround),
new Row([0, 1, 2].map((int i) {
return new Radio<int>(
value: i,
groupValue: _radioValue,
onChanged: _setRadioValue
);
}).toList(), justifyContent: FlexJustifyContent.spaceAround),
new Row([0, 1].map((int i) {
return new Radio<int>(value: i, groupValue: 0); // Disabled
}).toList(), justifyContent: FlexJustifyContent.spaceAround),
new Row([
new Switch(value: _switchValue, onChanged: _setSwitchValue),
new Switch(value: false), // Disabled
], justifyContent: FlexJustifyContent.spaceAround),
], justifyContent: FlexJustifyContent.spaceAround);
}
}
final WidgetDemo kSelectionControlsDemo = new WidgetDemo(
title: 'Selection Controls',
routeName: '/selection-controls',
builder: (_) => new SelectionControlsDemo()
);

View File

@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'demo/chip_demo.dart';
import 'demo/date_picker_demo.dart';
import 'demo/drop_down_demo.dart';
import 'demo/selection_controls_demo.dart';
import 'demo/slider_demo.dart';
import 'demo/time_picker_demo.dart';
import 'demo/widget_demo.dart';
@@ -14,6 +15,7 @@ import 'gallery_page.dart';
final List<WidgetDemo> _kDemos = <WidgetDemo>[
kChipDemo,
kSelectionControlsDemo,
kSliderDemo,
kDatePickerDemo,
kTimePickerDemo,