From 5846ffec570425692d2884669ea08b2c205123a4 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sat, 26 Sep 2015 13:16:33 -0700 Subject: [PATCH 1/2] Port address_book to fn3 --- .../examples/address_book/lib/main.dart | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/engine/src/flutter/examples/address_book/lib/main.dart b/engine/src/flutter/examples/address_book/lib/main.dart index 61f17891636..b46dffdc40d 100644 --- a/engine/src/flutter/examples/address_book/lib/main.dart +++ b/engine/src/flutter/examples/address_book/lib/main.dart @@ -3,9 +3,9 @@ // found in the LICENSE file. import 'package:sky/material.dart'; -import 'package:sky/widgets.dart'; +import 'package:sky/src/fn3.dart'; -class Field extends Component { +class Field extends StatelessComponent { Field({ Key key, this.inputKey, @@ -17,7 +17,7 @@ class Field extends Component { final String icon; final String placeholder; - Widget build() { + Widget build(BuildContext context) { return new Row([ new Padding( padding: const EdgeDims.symmetric(horizontal: 16.0), @@ -34,19 +34,22 @@ class Field extends Component { } } -class AddressBookApp extends App { +class AddressBookHome extends StatelessComponent { + AddressBookHome({ this.navigator }); - Widget buildToolBar(Navigator navigator) { + final NavigatorState navigator; + + Widget buildToolBar(BuildContext context) { return new ToolBar( left: new IconButton(icon: "navigation/arrow_back"), right: [new IconButton(icon: "navigation/check")] ); } - Widget buildFloatingActionButton(Navigator navigator) { + Widget buildFloatingActionButton(BuildContext context) { return new FloatingActionButton( child: new Icon(type: 'image/photo_camera', size: 24), - backgroundColor: Theme.of(this).accentColor + backgroundColor: Theme.of(context).accentColor ); } @@ -59,7 +62,7 @@ class AddressBookApp extends App { static final GlobalKey fillKey = new GlobalKey(); static final GlobalKey emoticonKey = new GlobalKey(); - Widget buildBody(Navigator navigator) { + Widget buildBody(BuildContext context) { return new Material( child: new Block([ new AspectRatio( @@ -78,45 +81,27 @@ class AddressBookApp extends App { ); } - Widget buildMain(Navigator navigator) { + Widget build(BuildContext context) { return new Scaffold( - toolbar: buildToolBar(navigator), - body: buildBody(navigator), - floatingActionButton: buildFloatingActionButton(navigator) - ); - } - - NavigationState _navigationState; - - void initState() { - _navigationState = new NavigationState([ - new Route( - name: '/', - builder: (navigator, route) => buildMain(navigator) - ), - ]); - super.initState(); - } - - Widget build() { - ThemeData theme = new ThemeData( - brightness: ThemeBrightness.light, - primarySwatch: Colors.teal, - accentColor: Colors.pinkAccent[100] - ); - return new Theme( - data: theme, - child: new DefaultTextStyle( - style: Typography.error, // if you see this, you've forgotten to correctly configure the text style! - child: new Title( - title: 'Address Book', - child: new Navigator(_navigationState) - ) - ) + toolbar: buildToolBar(context), + body: buildBody(context), + floatingActionButton: buildFloatingActionButton(context) ); } } +final ThemeData theme = new ThemeData( + brightness: ThemeBrightness.light, + primarySwatch: Colors.teal, + accentColor: Colors.pinkAccent[100] +); + void main() { - runApp(new AddressBookApp()); + runApp(new App( + title: 'Address Book', + theme: theme, + routes: { + '/': (NavigatorState navigator, Route route) => new AddressBookHome(navigator: navigator) + } + )); } From 7617feed0c150293fe17f762130a9467e010bb0a Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sat, 26 Sep 2015 13:18:20 -0700 Subject: [PATCH 2/2] Port hello_world to fn3 --- .../src/flutter/examples/hello_world/lib/main.dart | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/examples/hello_world/lib/main.dart b/engine/src/flutter/examples/hello_world/lib/main.dart index c8c7acb24d2..092c8b80953 100644 --- a/engine/src/flutter/examples/hello_world/lib/main.dart +++ b/engine/src/flutter/examples/hello_world/lib/main.dart @@ -2,14 +2,6 @@ // 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 HelloWorldApp extends App { - Widget build() { - return new Center(child: new Text('Hello, world!')); - } -} - -void main() { - runApp(new HelloWorldApp()); -} +void main() => runApp(new Center(child: new Text('Hello, world!')));