Commit d96cbdd0 authored by Adam Barth's avatar Adam Barth

Port demo_launcher and fitness to fn3

parent 8fb59f1d
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/painting.dart'; import 'package:sky/painting.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
AssetBundle _initBundle() { AssetBundle _initBundle() {
if (rootBundle != null) if (rootBundle != null)
...@@ -138,7 +138,7 @@ List<SkyDemo> demos = [ ...@@ -138,7 +138,7 @@ List<SkyDemo> demos = [
const double kCardHeight = 120.0; const double kCardHeight = 120.0;
const EdgeDims kListPadding = const EdgeDims.all(4.0); const EdgeDims kListPadding = const EdgeDims.all(4.0);
class DemoList extends Component { class DemoList extends StatelessComponent {
Widget buildCardContents(SkyDemo demo) { Widget buildCardContents(SkyDemo demo) {
return new Container( return new Container(
decoration: demo.decoration, decoration: demo.decoration,
...@@ -158,7 +158,7 @@ class DemoList extends Component { ...@@ -158,7 +158,7 @@ class DemoList extends Component {
); );
} }
Widget buildDemo(SkyDemo demo) { Widget buildDemo(BuildContext context, SkyDemo demo) {
return new GestureDetector( return new GestureDetector(
key: demo.key, key: demo.key,
onTap: () => launch(demo.href, demo.bundle), onTap: () => launch(demo.href, demo.bundle),
...@@ -171,7 +171,7 @@ class DemoList extends Component { ...@@ -171,7 +171,7 @@ class DemoList extends Component {
); );
} }
Widget build() { Widget build(BuildContext context) {
return new ScrollableList<SkyDemo>( return new ScrollableList<SkyDemo>(
items: demos, items: demos,
itemExtent: kCardHeight, itemExtent: kCardHeight,
...@@ -181,27 +181,29 @@ class DemoList extends Component { ...@@ -181,27 +181,29 @@ class DemoList extends Component {
} }
} }
class SkyHome extends App { final ThemeData _theme = new ThemeData(
Widget build() { brightness: ThemeBrightness.light,
return new Theme( primarySwatch: Colors.teal
data: new ThemeData( );
brightness: ThemeBrightness.light,
primarySwatch: Colors.teal class DemoHome extends StatelessComponent {
), Widget build(BuildContext context) {
child: new Title( return new Scaffold(
title: 'Sky Demos', toolbar: new ToolBar(center: new Text('Sky Demos')),
child: new Scaffold( body: new Material(
toolbar: new ToolBar(center: new Text('Sky Demos')), type: MaterialType.canvas,
body: new Material( child: new DemoList()
type: MaterialType.canvas,
child: new DemoList()
)
)
) )
); );
} }
} }
void main() { void main() {
runApp(new SkyHome()); runApp(new App(
title: 'Sky Demos',
theme: _theme,
routes: {
'/': (NavigatorState navigator, Route route) => new DemoHome()
}
));
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
part of fitness; part of fitness;
class FitnessItemList extends Component { class FitnessItemList extends StatelessComponent {
FitnessItemList({ Key key, this.items, this.onDismissed }) : super(key: key) { FitnessItemList({ Key key, this.items, this.onDismissed }) : super(key: key) {
assert(items != null); assert(items != null);
assert(onDismissed != null); assert(onDismissed != null);
...@@ -13,32 +13,26 @@ class FitnessItemList extends Component { ...@@ -13,32 +13,26 @@ class FitnessItemList extends Component {
final List<FitnessItem> items; final List<FitnessItem> items;
final FitnessItemHandler onDismissed; final FitnessItemHandler onDismissed;
Widget build() { Widget build(BuildContext context) {
return new Material( return new Material(
type: MaterialType.canvas, type: MaterialType.canvas,
child: new ScrollableList<FitnessItem>( child: new ScrollableList<FitnessItem>(
padding: const EdgeDims.all(4.0), padding: const EdgeDims.all(4.0),
items: items, items: items,
itemExtent: kFitnessItemHeight, itemExtent: kFitnessItemHeight,
itemBuilder: (item) => item.toRow(onDismissed: onDismissed) itemBuilder: (_, item) => item.toRow(onDismissed: onDismissed)
) )
); );
} }
} }
class DialogMenuItem extends ButtonBase { class DialogMenuItem extends StatelessComponent {
DialogMenuItem(this.children, { Key key, this.onPressed }) : super(key: key); DialogMenuItem(this.children, { Key key, this.onPressed }) : super(key: key);
List<Widget> children; List<Widget> children;
Function onPressed; Function onPressed;
void syncConstructorArguments(DialogMenuItem source) { Widget build(BuildContext context) {
children = source.children;
onPressed = source.onPressed;
super.syncConstructorArguments(source);
}
Widget buildContent() {
return new GestureDetector( return new GestureDetector(
onTap: onPressed, onTap: onPressed,
child: new Container( child: new Container(
...@@ -57,25 +51,16 @@ class DialogMenuItem extends ButtonBase { ...@@ -57,25 +51,16 @@ class DialogMenuItem extends ButtonBase {
class FeedFragment extends StatefulComponent { class FeedFragment extends StatefulComponent {
FeedFragment({ this.navigator, this.userData, this.onItemCreated, this.onItemDeleted }); FeedFragment({ this.navigator, this.userData, this.onItemCreated, this.onItemDeleted });
Navigator navigator; final NavigatorState navigator;
UserData userData; final UserData userData;
FitnessItemHandler onItemCreated; final FitnessItemHandler onItemCreated;
FitnessItemHandler onItemDeleted; final FitnessItemHandler onItemDeleted;
FitnessMode _fitnessMode = FitnessMode.feed; FeedFragmentState createState() => new FeedFragmentState();
}
void initState() {
// if (debug)
// new Timer(new Duration(seconds: 1), dumpState);
super.initState();
}
void syncConstructorArguments(FeedFragment source) { class FeedFragmentState extends State<FeedFragment> {
navigator = source.navigator; FitnessMode _fitnessMode = FitnessMode.feed;
userData = source.userData;
onItemCreated = source.onItemCreated;
onItemDeleted = source.onItemDeleted;
}
AnimationStatus _snackBarStatus = AnimationStatus.dismissed; AnimationStatus _snackBarStatus = AnimationStatus.dismissed;
bool _isShowingSnackBar = false; bool _isShowingSnackBar = false;
...@@ -94,7 +79,7 @@ class FeedFragment extends StatefulComponent { ...@@ -94,7 +79,7 @@ class FeedFragment extends StatefulComponent {
showing: _drawerShowing, showing: _drawerShowing,
level: 3, level: 3,
onDismissed: _handleDrawerDismissed, onDismissed: _handleDrawerDismissed,
navigator: navigator, navigator: config.navigator,
children: [ children: [
new DrawerHeader(child: new Text('Fitness')), new DrawerHeader(child: new Text('Fitness')),
new DrawerItem( new DrawerItem(
...@@ -136,8 +121,8 @@ class FeedFragment extends StatefulComponent { ...@@ -136,8 +121,8 @@ class FeedFragment extends StatefulComponent {
} }
void _handleShowSettings() { void _handleShowSettings() {
navigator.pop(); config.navigator.pop();
navigator.pushNamed('/settings'); config.navigator.pushNamed('/settings');
} }
// TODO(jackson): We should be localizing // TODO(jackson): We should be localizing
...@@ -160,7 +145,7 @@ class FeedFragment extends StatefulComponent { ...@@ -160,7 +145,7 @@ class FeedFragment extends StatefulComponent {
FitnessItem _undoItem; FitnessItem _undoItem;
void _handleItemDismissed(FitnessItem item) { void _handleItemDismissed(FitnessItem item) {
onItemDeleted(item); config.onItemDeleted(item);
setState(() { setState(() {
_undoItem = item; _undoItem = item;
_isShowingSnackBar = true; _isShowingSnackBar = true;
...@@ -174,7 +159,7 @@ class FeedFragment extends StatefulComponent { ...@@ -174,7 +159,7 @@ class FeedFragment extends StatefulComponent {
double startY; double startY;
double endY; double endY;
List<Point> dataSet = new List<Point>(); List<Point> dataSet = new List<Point>();
for (FitnessItem item in userData.items) { for (FitnessItem item in config.userData.items) {
if (item is Measurement) { if (item is Measurement) {
double x = item.when.millisecondsSinceEpoch.toDouble(); double x = item.when.millisecondsSinceEpoch.toDouble();
double y = item.weight; double y = item.weight;
...@@ -189,9 +174,9 @@ class FeedFragment extends StatefulComponent { ...@@ -189,9 +174,9 @@ class FeedFragment extends StatefulComponent {
dataSet.add(new Point(x, y)); dataSet.add(new Point(x, y));
} }
} }
if (userData.goalWeight != null && userData.goalWeight > 0.0) { if (config.userData.goalWeight != null && config.userData.goalWeight > 0.0) {
startY = math.min(startY, userData.goalWeight); startY = math.min(startY, config.userData.goalWeight);
endY = math.max(endY, userData.goalWeight); endY = math.max(endY, config.userData.goalWeight);
} }
playfair.ChartData data = new playfair.ChartData( playfair.ChartData data = new playfair.ChartData(
startX: startX, startX: startX,
...@@ -201,17 +186,17 @@ class FeedFragment extends StatefulComponent { ...@@ -201,17 +186,17 @@ class FeedFragment extends StatefulComponent {
dataSet: dataSet, dataSet: dataSet,
numHorizontalGridlines: 5, numHorizontalGridlines: 5,
roundToPlaces: 1, roundToPlaces: 1,
indicatorLine: userData.goalWeight, indicatorLine: config.userData.goalWeight,
indicatorText: "GOAL WEIGHT" indicatorText: "GOAL WEIGHT"
); );
return new playfair.Chart(data: data); return new playfair.Chart(data: data);
} }
Widget buildBody() { Widget buildBody() {
TextStyle style = Theme.of(this).text.title; TextStyle style = Theme.of(context).text.title;
if (userData == null) if (config.userData == null)
return new Material(type: MaterialType.canvas); return new Material(type: MaterialType.canvas);
if (userData.items.length == 0) if (config.userData.items.length == 0)
return new Material( return new Material(
type: MaterialType.canvas, type: MaterialType.canvas,
child: new Row( child: new Row(
...@@ -222,7 +207,7 @@ class FeedFragment extends StatefulComponent { ...@@ -222,7 +207,7 @@ class FeedFragment extends StatefulComponent {
switch (_fitnessMode) { switch (_fitnessMode) {
case FitnessMode.feed: case FitnessMode.feed:
return new FitnessItemList( return new FitnessItemList(
items: userData.items.reversed.toList(), items: config.userData.items.reversed.toList(),
onDismissed: _handleItemDismissed onDismissed: _handleItemDismissed
); );
case FitnessMode.chart: case FitnessMode.chart:
...@@ -237,7 +222,7 @@ class FeedFragment extends StatefulComponent { ...@@ -237,7 +222,7 @@ class FeedFragment extends StatefulComponent {
} }
void _handleUndo() { void _handleUndo() {
onItemCreated(_undoItem); config.onItemCreated(_undoItem);
setState(() { setState(() {
_undoItem = null; _undoItem = null;
_isShowingSnackBar = false; _isShowingSnackBar = false;
...@@ -256,9 +241,9 @@ class FeedFragment extends StatefulComponent { ...@@ -256,9 +241,9 @@ class FeedFragment extends StatefulComponent {
} }
void _handleActionButtonPressed() { void _handleActionButtonPressed() {
showDialog(navigator, (navigator) => new AddItemDialog(navigator)).then((routeName) { showDialog(config.navigator, (NavigatorState navigator) => new AddItemDialog(navigator)).then((routeName) {
if (routeName != null) if (routeName != null)
navigator.pushNamed(routeName); config.navigator.pushNamed(routeName);
}); });
} }
...@@ -274,7 +259,7 @@ class FeedFragment extends StatefulComponent { ...@@ -274,7 +259,7 @@ class FeedFragment extends StatefulComponent {
} }
} }
Widget build() { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
toolbar: buildToolBar(), toolbar: buildToolBar(),
body: buildBody(), body: buildBody(),
...@@ -288,12 +273,12 @@ class FeedFragment extends StatefulComponent { ...@@ -288,12 +273,12 @@ class FeedFragment extends StatefulComponent {
class AddItemDialog extends StatefulComponent { class AddItemDialog extends StatefulComponent {
AddItemDialog(this.navigator); AddItemDialog(this.navigator);
Navigator navigator; final NavigatorState navigator;
void syncConstructorArguments(AddItemDialog source) { AddItemDialogState createState() => new AddItemDialogState();
this.navigator = source.navigator; }
}
class AddItemDialogState extends State<AddItemDialog> {
// TODO(jackson): Internationalize // TODO(jackson): Internationalize
static final Map<String, String> _labels = { static final Map<String, String> _labels = {
'/measurements/new': 'Measure', '/measurements/new': 'Measure',
...@@ -308,7 +293,7 @@ class AddItemDialog extends StatefulComponent { ...@@ -308,7 +293,7 @@ class AddItemDialog extends StatefulComponent {
}); });
} }
Widget build() { Widget build(BuildContext context) {
List<Widget> menuItems = []; List<Widget> menuItems = [];
for(String routeName in _labels.keys) { for(String routeName in _labels.keys) {
menuItems.add(new DialogMenuItem([ menuItems.add(new DialogMenuItem([
...@@ -319,16 +304,16 @@ class AddItemDialog extends StatefulComponent { ...@@ -319,16 +304,16 @@ class AddItemDialog extends StatefulComponent {
return new Dialog( return new Dialog(
title: new Text("What are you doing?"), title: new Text("What are you doing?"),
content: new Block(menuItems), content: new Block(menuItems),
onDismiss: navigator.pop, onDismiss: config.navigator.pop,
actions: [ actions: [
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: navigator.pop onPressed: config.navigator.pop
), ),
new FlatButton( new FlatButton(
child: new Text('ADD'), child: new Text('ADD'),
onPressed: () { onPressed: () {
navigator.pop(_addItemRoute); config.navigator.pop(_addItemRoute);
} }
), ),
] ]
......
...@@ -26,7 +26,7 @@ abstract class FitnessItem { ...@@ -26,7 +26,7 @@ abstract class FitnessItem {
FitnessItemRow toRow({ FitnessItemHandler onDismissed }); FitnessItemRow toRow({ FitnessItemHandler onDismissed });
} }
abstract class FitnessItemRow extends Component { abstract class FitnessItemRow extends StatelessComponent {
FitnessItemRow({ FitnessItem item, this.onDismissed }) FitnessItemRow({ FitnessItem item, this.onDismissed })
: this.item = item, : this.item = item,
...@@ -37,9 +37,9 @@ abstract class FitnessItemRow extends Component { ...@@ -37,9 +37,9 @@ abstract class FitnessItemRow extends Component {
final FitnessItem item; final FitnessItem item;
final FitnessItemHandler onDismissed; final FitnessItemHandler onDismissed;
Widget buildContent(); Widget buildContent(BuildContext context);
Widget build() { Widget build(BuildContext context) {
return new Dismissable( return new Dismissable(
onDismissed: () => onDismissed(item), onDismissed: () => onDismissed(item),
child: new Container( child: new Container(
...@@ -51,10 +51,10 @@ abstract class FitnessItemRow extends Component { ...@@ -51,10 +51,10 @@ abstract class FitnessItemRow extends Component {
// stay put even when the tile is dismissed! // stay put even when the tile is dismissed!
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border( border: new Border(
bottom: new BorderSide(color: Theme.of(this).dividerColor) bottom: new BorderSide(color: Theme.of(context).dividerColor)
) )
), ),
child: buildContent() child: buildContent(context)
) )
); );
} }
......
...@@ -8,7 +8,7 @@ import 'package:playfair/playfair.dart' as playfair; ...@@ -8,7 +8,7 @@ import 'package:playfair/playfair.dart' as playfair;
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/painting.dart'; import 'package:sky/painting.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
import 'user_data.dart'; import 'user_data.dart';
import 'date_utils.dart'; import 'date_utils.dart';
...@@ -85,63 +85,53 @@ class UserDataImpl extends UserData { ...@@ -85,63 +85,53 @@ class UserDataImpl extends UserData {
} }
} }
class FitnessApp extends App { class FitnessApp extends StatefulComponent {
NavigationState _navigationState; FitnessAppState createState() => new FitnessAppState();
}
class FitnessAppState extends State<FitnessApp> {
UserDataImpl _userData; UserDataImpl _userData;
void didMount() { Map<String, RouteBuilder> _routes;
super.didMount();
void initState() {
super.initState();
loadFitnessData().then((UserData data) { loadFitnessData().then((UserData data) {
setState(() => _userData = data); setState(() => _userData = data);
}).catchError((e) { }).catchError((e) {
print("Failed to load data: $e"); print("Failed to load data: $e");
setState(() => _userData = new UserDataImpl()); setState(() => _userData = new UserDataImpl());
}); });
}
void initState() { _routes = {
_navigationState = new NavigationState([ '/': (NavigatorState navigator, Route route) {
new Route( return new FeedFragment(
name: '/',
builder: (navigator, route) => new FeedFragment(
navigator: navigator, navigator: navigator,
userData: _userData, userData: _userData,
onItemCreated: _handleItemCreated, onItemCreated: _handleItemCreated,
onItemDeleted: _handleItemDeleted onItemDeleted: _handleItemDeleted
) );
), },
new Route( '/meals/new': (navigator, route) {
name: '/meals/new', return new MealFragment(
builder: (navigator, route) => new MealFragment(
navigator: navigator, navigator: navigator,
onCreated: _handleItemCreated onCreated: _handleItemCreated
) );
), },
new Route( '/measurements/new': (NavigatorState navigator, Route route) {
name: '/measurements/new', return new MeasurementFragment(
builder: (navigator, route) => new MeasurementFragment(
navigator: navigator, navigator: navigator,
onCreated: _handleItemCreated onCreated: _handleItemCreated
) );
), },
new Route( '/settings': (navigator, route) {
name: '/settings', return new SettingsFragment(
builder: (navigator, route) => new SettingsFragment(
navigator: navigator, navigator: navigator,
userData: _userData, userData: _userData,
updater: settingsUpdater updater: settingsUpdater
) );
), }
]); };
super.initState();
}
void onBack() {
if (_navigationState.hasPrevious()) {
setState(() => _navigationState.pop());
} else {
super.onBack();
}
} }
void _handleItemCreated(FitnessItem item) { void _handleItemCreated(FitnessItem item) {
...@@ -168,17 +158,17 @@ class FitnessApp extends App { ...@@ -168,17 +158,17 @@ class FitnessApp extends App {
}); });
} }
Widget build() { final ThemeData _theme = new ThemeData(
return new Theme( brightness: ThemeBrightness.light,
data: new ThemeData( primarySwatch: Colors.indigo,
brightness: ThemeBrightness.light, accentColor: Colors.pinkAccent[200]
primarySwatch: Colors.indigo, );
accentColor: Colors.pinkAccent[200]
), Widget build(BuildContext) {
child: new Title( return new App(
title: 'Fitness', theme: _theme,
child: new Navigator(_navigationState) title: 'Fitness',
) routes: _routes
); );
} }
} }
......
...@@ -18,7 +18,7 @@ class MealRow extends FitnessItemRow { ...@@ -18,7 +18,7 @@ class MealRow extends FitnessItemRow {
MealRow({ Meal meal, FitnessItemHandler onDismissed }) MealRow({ Meal meal, FitnessItemHandler onDismissed })
: super(item: meal, onDismissed: onDismissed); : super(item: meal, onDismissed: onDismissed);
Widget buildContent() { Widget buildContent(BuildContext context) {
Meal meal = item; Meal meal = item;
List<Widget> children = [ List<Widget> children = [
new Flexible( new Flexible(
...@@ -30,42 +30,40 @@ class MealRow extends FitnessItemRow { ...@@ -30,42 +30,40 @@ class MealRow extends FitnessItemRow {
new Flexible( new Flexible(
child: new Text( child: new Text(
meal.displayDate, meal.displayDate,
style: Theme.of(this).text.caption.copyWith(textAlign: TextAlign.right) style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
) )
) )
]; ];
return new Row( return new Row(
children, children,
alignItems: FlexAlignItems.baseline, alignItems: FlexAlignItems.baseline,
textBaseline: DefaultTextStyle.of(this).textBaseline textBaseline: DefaultTextStyle.of(context).textBaseline
); );
} }
} }
class MealFragment extends StatefulComponent { class MealFragment extends StatefulComponent {
MealFragment({ this.navigator, this.onCreated }); MealFragment({ this.navigator, this.onCreated });
Navigator navigator; NavigatorState navigator;
FitnessItemHandler onCreated; FitnessItemHandler onCreated;
void syncConstructorArguments(MealFragment source) { MealFragmentState createState() => new MealFragmentState();
navigator = source.navigator; }
onCreated = source.onCreated;
}
class MealFragmentState extends State<MealFragment> {
String _description = ""; String _description = "";
void _handleSave() { void _handleSave() {
onCreated(new Meal(when: new DateTime.now(), description: _description)); config.onCreated(new Meal(when: new DateTime.now(), description: _description));
navigator.pop(); config.navigator.pop();
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/close", icon: "navigation/close",
onPressed: navigator.pop), onPressed: config.navigator.pop),
center: new Text('New Meal'), center: new Text('New Meal'),
right: [new InkWell( right: [new InkWell(
child: new GestureDetector( child: new GestureDetector(
...@@ -104,7 +102,7 @@ class MealFragment extends StatefulComponent { ...@@ -104,7 +102,7 @@ class MealFragment extends StatefulComponent {
); );
} }
Widget build() { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
toolbar: buildToolBar(), toolbar: buildToolBar(),
body: buildBody() body: buildBody()
......
...@@ -30,26 +30,26 @@ class MeasurementRow extends FitnessItemRow { ...@@ -30,26 +30,26 @@ class MeasurementRow extends FitnessItemRow {
MeasurementRow({ Measurement measurement, FitnessItemHandler onDismissed }) MeasurementRow({ Measurement measurement, FitnessItemHandler onDismissed })
: super(item: measurement, onDismissed: onDismissed); : super(item: measurement, onDismissed: onDismissed);
Widget buildContent() { Widget buildContent(BuildContext context) {
Measurement measurement = item; Measurement measurement = item;
List<Widget> children = [ List<Widget> children = [
new Flexible( new Flexible(
child: new Text( child: new Text(
measurement.displayWeight, measurement.displayWeight,
style: Theme.of(this).text.subhead style: Theme.of(context).text.subhead
) )
), ),
new Flexible( new Flexible(
child: new Text( child: new Text(
measurement.displayDate, measurement.displayDate,
style: Theme.of(this).text.caption.copyWith(textAlign: TextAlign.right) style: Theme.of(context).text.caption.copyWith(textAlign: TextAlign.right)
) )
) )
]; ];
return new Row( return new Row(
children, children,
alignItems: FlexAlignItems.baseline, alignItems: FlexAlignItems.baseline,
textBaseline: DefaultTextStyle.of(this).textBaseline textBaseline: DefaultTextStyle.of(context).textBaseline
); );
} }
} }
...@@ -57,17 +57,16 @@ class MeasurementRow extends FitnessItemRow { ...@@ -57,17 +57,16 @@ class MeasurementRow extends FitnessItemRow {
class MeasurementDateDialog extends StatefulComponent { class MeasurementDateDialog extends StatefulComponent {
MeasurementDateDialog({ this.navigator, this.previousDate }); MeasurementDateDialog({ this.navigator, this.previousDate });
Navigator navigator; final NavigatorState navigator;
DateTime previousDate; final DateTime previousDate;
MeasurementDateDialogState createState() => new MeasurementDateDialogState();
}
class MeasurementDateDialogState extends State<MeasurementDateDialog> {
@override @override
void initState() { void initState() {
_selectedDate = previousDate; _selectedDate = config.previousDate;
}
void syncConstructorArguments(MeasurementDateDialog source) {
navigator = source.navigator;
previousDate = source.previousDate;
} }
DateTime _selectedDate; DateTime _selectedDate;
...@@ -78,7 +77,7 @@ class MeasurementDateDialog extends StatefulComponent { ...@@ -78,7 +77,7 @@ class MeasurementDateDialog extends StatefulComponent {
}); });
} }
Widget build() { Widget build(BuildContext context) {
return new Dialog( return new Dialog(
content: new DatePicker( content: new DatePicker(
selectedDate: _selectedDate, selectedDate: _selectedDate,
...@@ -90,12 +89,12 @@ class MeasurementDateDialog extends StatefulComponent { ...@@ -90,12 +89,12 @@ class MeasurementDateDialog extends StatefulComponent {
actions: [ actions: [
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: navigator.pop onPressed: config.navigator.pop
), ),
new FlatButton( new FlatButton(
child: new Text('OK'), child: new Text('OK'),
onPressed: () { onPressed: () {
navigator.pop(_selectedDate); config.navigator.pop(_selectedDate);
} }
), ),
] ]
...@@ -104,17 +103,15 @@ class MeasurementDateDialog extends StatefulComponent { ...@@ -104,17 +103,15 @@ class MeasurementDateDialog extends StatefulComponent {
} }
class MeasurementFragment extends StatefulComponent { class MeasurementFragment extends StatefulComponent {
MeasurementFragment({ this.navigator, this.onCreated }); MeasurementFragment({ this.navigator, this.onCreated });
Navigator navigator; final NavigatorState navigator;
FitnessItemHandler onCreated; final FitnessItemHandler onCreated;
void syncConstructorArguments(MeasurementFragment source) { MeasurementFragmentState createState() => new MeasurementFragmentState();
navigator = source.navigator; }
onCreated = source.onCreated;
}
class MeasurementFragmentState extends State<MeasurementFragment> {
String _weight = ""; String _weight = "";
DateTime _when = new DateTime.now(); DateTime _when = new DateTime.now();
String _errorMessage = null; String _errorMessage = null;
...@@ -129,15 +126,15 @@ class MeasurementFragment extends StatefulComponent { ...@@ -129,15 +126,15 @@ class MeasurementFragment extends StatefulComponent {
_errorMessage = "Save failed"; _errorMessage = "Save failed";
}); });
} }
onCreated(new Measurement(when: _when, weight: parsedWeight)); config.onCreated(new Measurement(when: _when, weight: parsedWeight));
navigator.pop(); config.navigator.pop();
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/close", icon: "navigation/close",
onPressed: navigator.pop), onPressed: config.navigator.pop),
center: new Text('New Measurement'), center: new Text('New Measurement'),
right: [new InkWell( right: [new InkWell(
child: new GestureDetector( child: new GestureDetector(
...@@ -157,7 +154,7 @@ class MeasurementFragment extends StatefulComponent { ...@@ -157,7 +154,7 @@ class MeasurementFragment extends StatefulComponent {
static final GlobalKey weightKey = new GlobalKey(); static final GlobalKey weightKey = new GlobalKey();
void _handleDatePressed() { void _handleDatePressed() {
showDialog(navigator, (navigator) { showDialog(config.navigator, (NavigatorState navigator) {
return new MeasurementDateDialog(navigator: navigator, previousDate: _when); return new MeasurementDateDialog(navigator: navigator, previousDate: _when);
}).then((DateTime value) { }).then((DateTime value) {
if (value == null) if (value == null)
...@@ -168,7 +165,7 @@ class MeasurementFragment extends StatefulComponent { ...@@ -168,7 +165,7 @@ class MeasurementFragment extends StatefulComponent {
}); });
} }
Widget buildBody() { Widget buildBody(BuildContext context) {
Measurement measurement = new Measurement(when: _when); Measurement measurement = new Measurement(when: _when);
// TODO(jackson): Revisit the layout of this pane to be more maintainable // TODO(jackson): Revisit the layout of this pane to be more maintainable
return new Material( return new Material(
...@@ -182,7 +179,7 @@ class MeasurementFragment extends StatefulComponent { ...@@ -182,7 +179,7 @@ class MeasurementFragment extends StatefulComponent {
height: 50.0, height: 50.0,
child: new Column([ child: new Column([
new Text('Measurement Date'), new Text('Measurement Date'),
new Text(measurement.displayDate, style: Theme.of(this).text.caption), new Text(measurement.displayDate, style: Theme.of(context).text.caption),
], alignItems: FlexAlignItems.start) ], alignItems: FlexAlignItems.start)
) )
), ),
...@@ -204,10 +201,10 @@ class MeasurementFragment extends StatefulComponent { ...@@ -204,10 +201,10 @@ class MeasurementFragment extends StatefulComponent {
return new SnackBar(content: new Text(_errorMessage), showing: true); return new SnackBar(content: new Text(_errorMessage), showing: true);
} }
Widget build() { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
toolbar: buildToolBar(), toolbar: buildToolBar(),
body: buildBody(), body: buildBody(context),
snackBar: buildSnackBar() snackBar: buildSnackBar()
); );
} }
......
...@@ -10,38 +10,35 @@ typedef void SettingsUpdater({ ...@@ -10,38 +10,35 @@ typedef void SettingsUpdater({
}); });
class SettingsFragment extends StatefulComponent { class SettingsFragment extends StatefulComponent {
SettingsFragment({ this.navigator, this.userData, this.updater }); SettingsFragment({ this.navigator, this.userData, this.updater });
Navigator navigator; final NavigatorState navigator;
UserData userData; final UserData userData;
SettingsUpdater updater; final SettingsUpdater updater;
void syncConstructorArguments(SettingsFragment source) { SettingsFragmentState createState() => new SettingsFragmentState();
navigator = source.navigator; }
userData = source.userData;
updater = source.updater;
}
class SettingsFragmentState extends State<SettingsFragment> {
void _handleBackupChanged(bool value) { void _handleBackupChanged(bool value) {
assert(updater != null); assert(config.updater != null);
updater(backup: value ? BackupMode.enabled : BackupMode.disabled); config.updater(backup: value ? BackupMode.enabled : BackupMode.disabled);
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/arrow_back", icon: "navigation/arrow_back",
onPressed: navigator.pop), onPressed: config.navigator.pop
),
center: new Text('Settings') center: new Text('Settings')
); );
} }
String get goalWeightText { String get goalWeightText {
if (userData.goalWeight == null || userData.goalWeight == 0.0) if (config.userData.goalWeight == null || config.userData.goalWeight == 0.0)
return "None"; return "None";
else return "${config.userData.goalWeight}";
return "${userData.goalWeight}";
} }
static final GlobalKey weightGoalKey = new GlobalKey(); static final GlobalKey weightGoalKey = new GlobalKey();
...@@ -51,7 +48,7 @@ class SettingsFragment extends StatefulComponent { ...@@ -51,7 +48,7 @@ class SettingsFragment extends StatefulComponent {
void _handleGoalWeightChanged(String goalWeight) { void _handleGoalWeightChanged(String goalWeight) {
// TODO(jackson): Looking for null characters to detect enter key is a hack // TODO(jackson): Looking for null characters to detect enter key is a hack
if (goalWeight.endsWith("\u{0}")) { if (goalWeight.endsWith("\u{0}")) {
navigator.pop(double.parse(goalWeight.replaceAll("\u{0}", ""))); config.navigator.pop(double.parse(goalWeight.replaceAll("\u{0}", "")));
} else { } else {
setState(() { setState(() {
try { try {
...@@ -64,7 +61,7 @@ class SettingsFragment extends StatefulComponent { ...@@ -64,7 +61,7 @@ class SettingsFragment extends StatefulComponent {
} }
void _handleGoalWeightPressed() { void _handleGoalWeightPressed() {
showDialog(navigator, (navigator) { showDialog(config.navigator, (NavigatorState navigator) {
return new Dialog( return new Dialog(
title: new Text("Goal Weight"), title: new Text("Goal Weight"),
content: new Input( content: new Input(
...@@ -91,10 +88,10 @@ class SettingsFragment extends StatefulComponent { ...@@ -91,10 +88,10 @@ class SettingsFragment extends StatefulComponent {
), ),
] ]
); );
}).then((double goalWeight) => updater(goalWeight: goalWeight)); }).then((double goalWeight) => config.updater(goalWeight: goalWeight));
} }
Widget buildSettingsPane() { Widget buildSettingsPane(BuildContext context) {
return new Material( return new Material(
type: MaterialType.canvas, type: MaterialType.canvas,
child: new ScrollableViewport( child: new ScrollableViewport(
...@@ -102,17 +99,17 @@ class SettingsFragment extends StatefulComponent { ...@@ -102,17 +99,17 @@ class SettingsFragment extends StatefulComponent {
padding: const EdgeDims.symmetric(vertical: 20.0), padding: const EdgeDims.symmetric(vertical: 20.0),
child: new BlockBody([ child: new BlockBody([
new DrawerItem( new DrawerItem(
onPressed: () { _handleBackupChanged(!(userData.backupMode == BackupMode.enabled)); }, onPressed: () { _handleBackupChanged(!(config.userData.backupMode == BackupMode.enabled)); },
child: new Row([ child: new Row([
new Flexible(child: new Text('Back up data to the cloud')), new Flexible(child: new Text('Back up data to the cloud')),
new Switch(value: userData.backupMode == BackupMode.enabled, onChanged: _handleBackupChanged), new Switch(value: config.userData.backupMode == BackupMode.enabled, onChanged: _handleBackupChanged),
]) ])
), ),
new DrawerItem( new DrawerItem(
onPressed: () => _handleGoalWeightPressed(), onPressed: () => _handleGoalWeightPressed(),
child: new Column([ child: new Column([
new Text('Goal Weight'), new Text('Goal Weight'),
new Text(goalWeightText, style: Theme.of(this).text.caption), new Text(goalWeightText, style: Theme.of(context).text.caption),
], ],
alignItems: FlexAlignItems.start alignItems: FlexAlignItems.start
) )
...@@ -123,10 +120,10 @@ class SettingsFragment extends StatefulComponent { ...@@ -123,10 +120,10 @@ class SettingsFragment extends StatefulComponent {
); );
} }
Widget build() { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
toolbar: buildToolBar(), toolbar: buildToolBar(),
body: buildSettingsPane() body: buildSettingsPane(context)
); );
} }
} }
...@@ -16,7 +16,7 @@ import 'package:sky/src/fn3/scrollable.dart'; ...@@ -16,7 +16,7 @@ import 'package:sky/src/fn3/scrollable.dart';
import 'package:sky/src/fn3/theme.dart'; import 'package:sky/src/fn3/theme.dart';
import 'package:sky/src/fn3/transitions.dart'; import 'package:sky/src/fn3/transitions.dart';
typedef Dialog DialogBuilder(NavigatorState navigator); typedef Widget DialogBuilder(NavigatorState navigator);
/// A material design dialog /// A material design dialog
/// ///
......
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