Commit cefbfa3b authored by Adam Barth's avatar Adam Barth

Port Date Picker example to fn3

parent 878775bb
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
class ContainerApp extends App { class ContainerApp extends StatelessComponent {
Widget build() { Widget build(BuildContext context) {
return new Column([ return new Column([
new Container( new Container(
padding: new EdgeDims.all(10.0), padding: new EdgeDims.all(10.0),
margin: new EdgeDims.all(10.0), margin: new EdgeDims.all(10.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)), decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new NetworkImage( child: new NetworkImage(
src: "https://www.dartlang.org/logos/dart-logo.png", src: "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png",
width: 300.0, width: 300.0,
height: 300.0 height: 300.0
) )
......
...@@ -2,27 +2,30 @@ ...@@ -2,27 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
void main() => runApp(new DatePickerDemo()); void main() => runApp(new DatePickerDemo());
class DatePickerDemo extends App { class DatePickerDemo extends StatefulComponent {
DatePickerDemoState createState() => new DatePickerDemoState(this);
DateTime _dateTime; }
void initState() { class DatePickerDemoState extends ComponentState<DatePickerDemo> {
DatePickerDemoState(DatePickerDemo config) : super(config) {
DateTime now = new DateTime.now(); DateTime now = new DateTime.now();
_dateTime = new DateTime(now.year, now.month, now.day); _dateTime = new DateTime(now.year, now.month, now.day);
} }
DateTime _dateTime;
void _handleDateChanged(DateTime dateTime) { void _handleDateChanged(DateTime dateTime) {
setState(() { setState(() {
_dateTime = dateTime; _dateTime = dateTime;
}); });
} }
Widget build() { Widget build(BuildContext context) {
return new Theme( return new Theme(
data: new ThemeData( data: new ThemeData(
brightness: ThemeBrightness.light, brightness: ThemeBrightness.light,
......
...@@ -8,7 +8,7 @@ import 'package:sky/src/fn3/framework.dart'; ...@@ -8,7 +8,7 @@ import 'package:sky/src/fn3/framework.dart';
abstract class ButtonState<T extends StatefulComponent> extends ComponentState<T> { abstract class ButtonState<T extends StatefulComponent> extends ComponentState<T> {
ButtonState(T config) : super(config); ButtonState(T config) : super(config);
bool highlight; bool highlight = false;
void _handlePointerDown(_) { void _handlePointerDown(_) {
setState(() { setState(() {
......
...@@ -11,12 +11,14 @@ import 'package:sky/src/fn3/material.dart'; ...@@ -11,12 +11,14 @@ import 'package:sky/src/fn3/material.dart';
// Rather than using this class directly, please use FlatButton or RaisedButton. // Rather than using this class directly, please use FlatButton or RaisedButton.
abstract class MaterialButton extends StatefulComponent { abstract class MaterialButton extends StatefulComponent {
const MaterialButton({ MaterialButton({
Key key, Key key,
this.child, this.child,
this.enabled: true, this.enabled: true,
this.onPressed this.onPressed
}) : super(key: key); }) : super(key: key) {
assert(enabled != null);
}
final Widget child; final Widget child;
final bool enabled; final bool enabled;
......
...@@ -17,7 +17,9 @@ class RaisedButton extends MaterialButton { ...@@ -17,7 +17,9 @@ class RaisedButton extends MaterialButton {
}) : super(key: key, }) : super(key: key,
child: child, child: child,
enabled: enabled, enabled: enabled,
onPressed: onPressed); onPressed: onPressed) {
assert(enabled != null);
}
RaisedButtonState createState() => new RaisedButtonState(this); RaisedButtonState createState() => new RaisedButtonState(this);
} }
......
...@@ -218,8 +218,9 @@ class ScaffoldElement extends RenderObjectElement<Scaffold> { ...@@ -218,8 +218,9 @@ class ScaffoldElement extends RenderObjectElement<Scaffold> {
super.mount(parent, newSlot); super.mount(parent, newSlot);
_children = new Map<ScaffoldSlots, Element>(); _children = new Map<ScaffoldSlots, Element>();
for (ScaffoldSlots slot in ScaffoldSlots.values) { for (ScaffoldSlots slot in ScaffoldSlots.values) {
_children[slot] = widget._children[slot].createElement() Element newChild = widget._children[slot]?.createElement();
..mount(this, slot); _children[slot] = newChild;
newChild?.mount(this, slot);
} }
} }
......
...@@ -40,12 +40,7 @@ abstract class Scrollable extends StatefulComponent { ...@@ -40,12 +40,7 @@ abstract class Scrollable extends StatefulComponent {
} }
abstract class ScrollableState<T extends Scrollable> extends ComponentState<T> { abstract class ScrollableState<T extends Scrollable> extends ComponentState<T> {
ScrollableState(T config) : super(config); ScrollableState(T config) : super(config) {
AnimatedSimulation _toEndAnimation; // See _startToEndAnimation()
ValueAnimation<double> _toOffsetAnimation; // Started by scrollTo()
void initState(BuildContext context) {
if (config.initialScrollOffset is double) if (config.initialScrollOffset is double)
_scrollOffset = config.initialScrollOffset; _scrollOffset = config.initialScrollOffset;
_toEndAnimation = new AnimatedSimulation(_setScrollOffset); _toEndAnimation = new AnimatedSimulation(_setScrollOffset);
...@@ -56,6 +51,9 @@ abstract class ScrollableState<T extends Scrollable> extends ComponentState<T> { ...@@ -56,6 +51,9 @@ abstract class ScrollableState<T extends Scrollable> extends ComponentState<T> {
}); });
} }
AnimatedSimulation _toEndAnimation; // See _startToEndAnimation()
ValueAnimation<double> _toOffsetAnimation; // Started by scrollTo()
double _scrollOffset = 0.0; double _scrollOffset = 0.0;
double get scrollOffset => _scrollOffset; double get scrollOffset => _scrollOffset;
......
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