Commit 878775bb authored by Adam Barth's avatar Adam Barth

Port big_switch.dart to fn3

parent 0206f1a6
...@@ -3,9 +3,19 @@ ...@@ -3,9 +3,19 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
class BigSwitch extends StatefulComponent {
BigSwitch({ this.scale });
final double scale;
BigSwitchState createState() => new BigSwitchState(this);
}
class BigSwitchState extends ComponentState<BigSwitch> {
BigSwitchState(BigSwitch config) : super(config);
class BigSwitchApp extends App {
bool _value = false; bool _value = false;
void _handleOnChanged(bool value) { void _handleOnChanged(bool value) {
...@@ -14,20 +24,22 @@ class BigSwitchApp extends App { ...@@ -14,20 +24,22 @@ class BigSwitchApp extends App {
}); });
} }
Widget build() { Widget build(BuildContext context) {
Matrix4 scale = new Matrix4.identity(); Matrix4 scale = new Matrix4.identity();
scale.scale(5.0, 5.0); scale.scale(config.scale, config.scale);
return new Container( return new Transform(
child: new Switch(value: _value, onChanged: _handleOnChanged), transform: scale,
padding: new EdgeDims.all(20.0), child: new Switch(value: _value, onChanged: _handleOnChanged)
transform: scale,
decoration: new BoxDecoration(
backgroundColor: Colors.teal[600]
)
); );
} }
} }
void main() { void main() {
runApp(new BigSwitchApp()); runApp(new Container(
child: new BigSwitch(scale: 5.0),
padding: new EdgeDims.all(20.0),
decoration: new BoxDecoration(
backgroundColor: Colors.teal[600]
)
));
} }
...@@ -4,7 +4,45 @@ ...@@ -4,7 +4,45 @@
library fn3; library fn3;
export 'fn3/animated_component.dart';
export 'fn3/basic.dart'; export 'fn3/basic.dart';
export 'fn3/framework.dart';
export 'fn3/binding.dart'; export 'fn3/binding.dart';
export 'fn3/button_state.dart';
export 'fn3/card.dart';
export 'fn3/checkbox.dart';
export 'fn3/date_picker.dart';
export 'fn3/dialog.dart';
export 'fn3/dismissable.dart';
export 'fn3/drag_target.dart';
export 'fn3/drawer.dart';
export 'fn3/drawer_divider.dart';
export 'fn3/drawer_header.dart';
export 'fn3/drawer_item.dart';
export 'fn3/flat_button.dart';
export 'fn3/floating_action_button.dart';
export 'fn3/focus.dart';
export 'fn3/framework.dart';
export 'fn3/gesture_detector.dart';
export 'fn3/homogeneous_viewport.dart'; export 'fn3/homogeneous_viewport.dart';
export 'fn3/icon_button.dart';
export 'fn3/icon.dart';
export 'fn3/ink_well.dart';
export 'fn3/material_button.dart';
export 'fn3/material.dart';
export 'fn3/navigator.dart';
export 'fn3/popup_menu.dart';
export 'fn3/popup_menu_item.dart';
export 'fn3/progress_indicator.dart';
export 'fn3/radio.dart';
export 'fn3/raised_button.dart';
export 'fn3/scaffold.dart';
export 'fn3/scrollable.dart';
export 'fn3/snack_bar.dart';
export 'fn3/switch.dart';
export 'fn3/tabs.dart';
export 'fn3/theme.dart';
export 'fn3/title.dart';
export 'fn3/tool_bar.dart';
export 'fn3/transitions.dart';
export 'package:vector_math/vector_math.dart' show Matrix4;
...@@ -27,24 +27,40 @@ const Duration _kCheckDuration = const Duration(milliseconds: 200); ...@@ -27,24 +27,40 @@ const Duration _kCheckDuration = const Duration(milliseconds: 200);
const Size _kSwitchSize = const Size(_kSwitchWidth + 2.0, _kSwitchHeight + 2.0); const Size _kSwitchSize = const Size(_kSwitchWidth + 2.0, _kSwitchHeight + 2.0);
const double _kReactionRadius = _kSwitchWidth / 2.0; const double _kReactionRadius = _kSwitchWidth / 2.0;
class Switch extends LeafRenderObjectWidget { class Switch extends StatelessComponent {
Switch({ Key key, this.value, this.onChanged }) Switch({ Key key, this.value, this.onChanged })
: super(key: key); : super(key: key);
final bool value; final bool value;
final ValueChanged onChanged; final ValueChanged onChanged;
Widget build(BuildContext context) {
return new _SwitchWrapper(
value: value,
thumbColor: Theme.of(context).accentColor,
onChanged: onChanged
);
}
}
class _SwitchWrapper extends LeafRenderObjectWidget {
_SwitchWrapper({ Key key, this.value, this.thumbColor, this.onChanged })
: super(key: key);
final bool value;
final Color thumbColor;
final ValueChanged onChanged;
_RenderSwitch createRenderObject() => new _RenderSwitch( _RenderSwitch createRenderObject() => new _RenderSwitch(
value: value, value: value,
thumbColor: null, thumbColor: thumbColor,
onChanged: onChanged onChanged: onChanged
); );
void updateRenderObject(_RenderSwitch renderObject, Switch oldWidget) { void updateRenderObject(_RenderSwitch renderObject, _SwitchWrapper oldWidget) {
renderObject.value = value; renderObject.value = value;
renderObject.thumbColor = thumbColor;
renderObject.onChanged = onChanged; renderObject.onChanged = onChanged;
// TODO(abarth): How do we get the current theme here?
// renderObject.thumbColor = Theme.of(this).accentColor;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment