Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4. runApp(new MyApp());
  5. }
  6.  
  7. class SandyShores extends StatelessWidget {
  8. static String routeName = "sandyShores";
  9.  
  10. @override
  11. Widget build(BuildContext context) {
  12. return new Center(child: new Text("You've landed on the Sandy Shores!"));
  13. }
  14.  
  15. }
  16.  
  17. class MyApp extends StatelessWidget {
  18. // This widget is the root of your application.
  19. @override
  20. Widget build(BuildContext context) {
  21. var routes = <String, WidgetBuilder> {
  22. SandyShores.routeName : (BuildContext context) => new SandyShores(),
  23. };
  24.  
  25. return new MaterialApp(
  26. title: 'Flutter Demo',
  27. theme: new ThemeData(
  28. // This is the theme of your application.
  29. //
  30. // Try running your application with "flutter run". You'll see
  31. // the application has a blue toolbar. Then, without quitting
  32. // the app, try changing the primarySwatch below to Colors.green
  33. // and press "r" in the console where you ran "flutter run".
  34. // We call this a "hot reload". Notice that the counter didn't
  35. // reset back to zero -- the application is not restarted.
  36. primarySwatch: Colors.blue,
  37. ),
  38.  
  39. home: new MyHomePage(title: 'Flutter Demo Home Page'),
  40.  
  41. // home: new ColorPage(),
  42.  
  43. routes: routes,
  44. );
  45. }
  46. }
  47.  
  48. class ColorPage extends StatefulWidget {
  49. @override
  50. State<StatefulWidget> createState() => new ColorPageState();
  51. }
  52.  
  53. class ColorPageState extends State<ColorPage> {
  54.  
  55. var _color = Colors.blue[400];
  56.  
  57. @override
  58. Widget build(BuildContext context) {
  59. var item2 = new Container(width: 50.0, height: 50.0, color: _color);
  60.  
  61. var buttonText = new Text('Click');
  62.  
  63. var item1 = new RaisedButton(child: buttonText, onPressed: _onButonPressed);
  64.  
  65. var items = [item1, item2];
  66.  
  67. var row = new Row(children: items);
  68.  
  69. var center = new Center(child: row);
  70.  
  71. Scaffold scaffold = new Scaffold(body: center);
  72.  
  73. return scaffold;
  74. }
  75.  
  76.  
  77. void _onButonPressed() {
  78.  
  79. setState(() {
  80. if (_color == Colors.blue[400]) {
  81. _color = Colors.red[400];
  82. } else {
  83. _color = Colors.blue[400];
  84. }
  85. });
  86.  
  87. }
  88.  
  89. }
  90.  
  91. class MyHomePage extends StatefulWidget {
  92. MyHomePage({Key key, this.title}) : super(key: key);
  93.  
  94. // This widget is the home page of your application. It is stateful,
  95. // meaning that it has a State object (defined below) that contains
  96. // fields that affect how it looks.
  97.  
  98. // This class is the configuration for the state. It holds the
  99. // values (in this case the title) provided by the parent (in this
  100. // case the App widget) and used by the build method of the State.
  101. // Fields in a Widget subclass are always marked "final".
  102.  
  103. final String title;
  104.  
  105. @override
  106. _MyHomePageState createState() => new _MyHomePageState();
  107. }
  108.  
  109. class _MyHomePageState extends State<MyHomePage> {
  110. int _counter = 0;
  111.  
  112. void _incrementCounter() {
  113. setState(() {
  114. // This call to setState tells the Flutter framework that
  115. // something has changed in this State, which causes it to rerun
  116. // the build method below so that the display can reflect the
  117. // updated values. If we changed _counter without calling
  118. // setState(), then the build method would not be called again,
  119. // and so nothing would appear to happen.
  120. _counter++;
  121. });
  122. }
  123.  
  124. @override
  125. Widget build(BuildContext context) {
  126. var headerText = new Text('Headers');
  127.  
  128. var header = new DrawerHeader(child: headerText);
  129.  
  130. var item1Text = new Text('Sandy Shores');
  131.  
  132. var item1Icon = new Icon(Icons.settings);
  133.  
  134. //var item1 = new DrawerItem(child: item1Text, icon: item1Icon, onPressed: _onItem1OnPressed);
  135. // Chant to:
  136. var item1 = new ListTile(leading: item1Icon, trailing: item1Text, onTap: _onItem1OnPressed);
  137.  
  138. var children = [header, item1];
  139.  
  140. var listView = new ListView(children: children);
  141.  
  142. var drawer = new Drawer(child: listView);
  143.  
  144. // This method is rerun every time setState is called, for instance
  145. // as done by the _incrementCounter method above.
  146. // The Flutter framework has been optimized to make rerunning
  147. // build methods fast, so that you can just rebuild anything that
  148. // needs updating rather than having to individually change
  149. // instances of widgets.
  150. return new Scaffold(
  151. drawer: drawer,
  152. appBar: new AppBar(
  153. // Here we take the value from the MyHomePage object that
  154. // was created by the App.build method, and use it to set
  155. // our appbar title.
  156. title: new Text(config.title),
  157. ),
  158. body: new Center(
  159. child: new Text(
  160. 'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.',
  161. ),
  162. ),
  163. floatingActionButton: new FloatingActionButton(
  164. onPressed: _incrementCounter,
  165. tooltip: 'Increment',
  166. child: new Icon(Icons.add),
  167. ), // This trailing comma tells the Dart formatter to use
  168. // a style that looks nicer for build methods.
  169. );
  170. }
  171.  
  172.  
  173. void _onItem1OnPressed() {
  174. Navigator.popAndPushNamed(context, SandyShores.routeName);
  175. }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement