Commit cefbfa3b authored by Adam Barth's avatar Adam Barth

Port Date Picker example to fn3

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