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:
@@ -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()
|
||||
);
|
||||
@@ -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,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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';
|
||||
|
||||
class BigSwitch extends StatefulComponent {
|
||||
BigSwitch({ this.scale });
|
||||
|
||||
final double scale;
|
||||
|
||||
BigSwitchState createState() => new BigSwitchState();
|
||||
}
|
||||
|
||||
class BigSwitchState extends State<BigSwitch> {
|
||||
bool _value = false;
|
||||
|
||||
void _handleOnChanged(bool value) {
|
||||
setState(() {
|
||||
_value = value;
|
||||
});
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
Matrix4 scale = new Matrix4.identity();
|
||||
scale.scale(config.scale, config.scale);
|
||||
return new Transform(
|
||||
transform: scale,
|
||||
child: new Switch(value: _value, onChanged: _handleOnChanged)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new Container(
|
||||
child: new BigSwitch(scale: 5.0),
|
||||
padding: new EdgeDims.all(20.0),
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: Colors.teal[600]
|
||||
)
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user