|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 | import 'package:flutter_driver/driver_extension.dart';
|
| 3 | +import 'package:functional_widget_annotation/functional_widget_annotation.dart'; |
| 4 | +import 'package:hello_world/stream.dart'; |
| 5 | + |
| 6 | +part 'main.g.dart'; |
3 | 7 |
|
4 | 8 | void main() {
|
5 | 9 | enableFlutterDriverExtension();
|
| 10 | + init(); |
6 | 11 | runApp(MyApp());
|
7 | 12 | }
|
8 | 13 |
|
9 |
| -class MyApp extends StatelessWidget { |
10 |
| - @override |
11 |
| - Widget build(BuildContext context) { |
12 |
| - return MaterialApp( |
13 |
| - title: 'Counter App', |
14 |
| - home: MyHomePage(title: 'Counter App Home Page'), |
15 |
| - ); |
16 |
| - } |
17 |
| -} |
18 |
| - |
19 |
| -class MyHomePage extends StatefulWidget { |
20 |
| - MyHomePage({Key key, this.title}) : super(key: key); |
| 14 | +@widget |
| 15 | +Widget myApp() => MaterialApp( |
| 16 | + title: 'Counter App', |
| 17 | + home: MyHomePage(title: 'Counter App Home Page'), |
| 18 | +); |
21 | 19 |
|
22 |
| - final String title; |
23 |
| - |
24 |
| - @override |
25 |
| - _MyHomePageState createState() => _MyHomePageState(); |
26 |
| -} |
27 | 20 |
|
28 |
| -class _MyHomePageState extends State<MyHomePage> { |
29 |
| - int _counter = 0; |
30 | 21 |
|
31 |
| - void _incrementCounter() { |
32 |
| - setState(() { |
33 |
| - _counter++; |
34 |
| - }); |
35 |
| - } |
36 |
| - |
37 |
| - @override |
38 |
| - Widget build(BuildContext context) { |
39 |
| - return Scaffold( |
40 |
| - appBar: AppBar( |
41 |
| - title: Text(widget.title), |
42 |
| - ), |
43 |
| - body: Center( |
44 |
| - child: Column( |
45 |
| - mainAxisAlignment: MainAxisAlignment.center, |
46 |
| - children: <Widget>[ |
47 |
| - Text( |
48 |
| - 'You have pushed the button this many times:', |
49 |
| - ), |
50 |
| - Tooltip( |
51 |
| - message: 'counter_tooltip', |
52 |
| - child: Text( |
53 |
| - '$_counter', |
| 22 | +@widget |
| 23 | +Widget myHomePage(BuildContext context, {String title}) => Scaffold( |
| 24 | + appBar: AppBar( |
| 25 | + title: Text(title), |
| 26 | + ), |
| 27 | + body: Center( |
| 28 | + child: Column( |
| 29 | + mainAxisAlignment: MainAxisAlignment.center, |
| 30 | + children: <Widget>[ |
| 31 | + Text( |
| 32 | + 'You have pushed the button this many times:', |
| 33 | + ), |
| 34 | + Tooltip( |
| 35 | + message: 'counter_tooltip', |
| 36 | + child: StreamBuilder<int>( |
| 37 | + stream: counterStream, |
| 38 | + builder: (context, snapshot) { |
| 39 | + return Text( |
| 40 | + '${snapshot.data}', |
54 | 41 | key: Key('counter'),
|
55 | 42 | style: Theme.of(context).textTheme.display1,
|
56 | 43 | semanticsLabel: 'counter_semantic',
|
57 |
| - ), |
58 |
| - ), |
59 |
| - FlatButton( |
60 |
| - onPressed: () { |
61 |
| - Navigator.push( |
62 |
| - context, |
63 |
| - MaterialPageRoute( |
64 |
| - builder: (context) => Scaffold( |
65 |
| - appBar: AppBar( |
66 |
| - title: Text("Second Route"), |
67 |
| - ), |
68 |
| - body: Center( |
69 |
| - child: SecondPage(), |
70 |
| - ), |
71 |
| - )), |
72 |
| - ); |
73 |
| - }, |
74 |
| - child: Text( |
75 |
| - 'Go to next route', |
76 |
| - key: Key('next_route_key'), |
77 |
| - ), |
78 |
| - ), |
79 |
| - ], |
80 |
| - ), |
81 |
| - ), |
82 |
| - floatingActionButton: FloatingActionButton( |
83 |
| - // Provide a Key to this button. This allows finding this |
84 |
| - // specific button inside the test suite, and tapping it. |
85 |
| - key: Key('increment'), |
86 |
| - onPressed: _incrementCounter, |
87 |
| - tooltip: 'Increment', |
88 |
| - child: Icon(Icons.add), |
89 |
| - ), |
90 |
| - ); |
91 |
| - } |
92 |
| -} |
93 |
| - |
94 |
| -class SecondPage extends StatelessWidget { |
95 |
| - @override |
96 |
| - Widget build(BuildContext context) => ListView( |
97 |
| - padding: const EdgeInsets.all(8.0), |
98 |
| - children: <Widget>[ |
99 |
| - Container( |
100 |
| - height: 100, |
101 |
| - color: Colors.amber[600], |
102 |
| - child: const Center(child: Text('This is 2nd route')), |
103 |
| - ), |
104 |
| - Container( |
105 |
| - height: 200, |
106 |
| - color: Colors.amber[500], |
107 |
| - child: const Center(child: Text('Entry B')), |
108 |
| - ), |
109 |
| - Container( |
110 |
| - height: 500, |
111 |
| - color: Colors.amber[100], |
112 |
| - child: const Center(child: Text('Entry C')), |
| 44 | + ); |
| 45 | + } |
113 | 46 | ),
|
114 |
| - Container( |
115 |
| - height: 1000, |
116 |
| - color: Colors.amber[100], |
117 |
| - child: const Center(child: Text('Entry D')), |
118 |
| - ), |
119 |
| - Container( |
120 |
| - height: 1000, |
121 |
| - color: Colors.amber[100], |
122 |
| - child: const Center( |
123 |
| - child: TextField( |
124 |
| - decoration: InputDecoration( |
125 |
| - border: OutlineInputBorder(), |
126 |
| - labelText: 'Sample Input', |
127 |
| - ), |
128 |
| - )), |
| 47 | + ), |
| 48 | + FlatButton( |
| 49 | + onPressed: () { |
| 50 | + Navigator.push( |
| 51 | + context, |
| 52 | + MaterialPageRoute( |
| 53 | + builder: (context) => Scaffold( |
| 54 | + appBar: AppBar( |
| 55 | + title: Text("Second Route"), |
| 56 | + ), |
| 57 | + body: Center( |
| 58 | + child: SecondPage(), |
| 59 | + ), |
| 60 | + )), |
| 61 | + ); |
| 62 | + }, |
| 63 | + child: Text( |
| 64 | + 'Go to next route', |
| 65 | + key: Key('next_route_key'), |
129 | 66 | ),
|
130 |
| - ], |
131 |
| - ); |
132 |
| -} |
| 67 | + ), |
| 68 | + ], |
| 69 | + ), |
| 70 | + ), |
| 71 | + floatingActionButton: FloatingActionButton( |
| 72 | + // Provide a Key to this button. This allows finding this |
| 73 | + // specific button inside the test suite, and tapping it. |
| 74 | + key: Key('increment'), |
| 75 | + onPressed: () => plusClickSink.add(null), |
| 76 | + tooltip: 'Increment', |
| 77 | + child: Icon(Icons.add), |
| 78 | + ), |
| 79 | +); |
| 80 | + |
| 81 | +@widget |
| 82 | +Widget secondPage() => ListView( |
| 83 | + padding: const EdgeInsets.all(8.0), |
| 84 | + children: <Widget>[ |
| 85 | + Container( |
| 86 | + height: 100, |
| 87 | + color: Colors.amber[600], |
| 88 | + child: const Center(child: Text('This is 2nd route')), |
| 89 | + ), |
| 90 | + Container( |
| 91 | + height: 200, |
| 92 | + color: Colors.amber[500], |
| 93 | + child: const Center(child: Text('Entry B')), |
| 94 | + ), |
| 95 | + Container( |
| 96 | + height: 500, |
| 97 | + color: Colors.amber[100], |
| 98 | + child: const Center(child: Text('Entry C')), |
| 99 | + ), |
| 100 | + Container( |
| 101 | + height: 1000, |
| 102 | + color: Colors.amber[100], |
| 103 | + child: const Center(child: Text('Entry D')), |
| 104 | + ), |
| 105 | + Container( |
| 106 | + height: 1000, |
| 107 | + color: Colors.amber[100], |
| 108 | + child: const Center( |
| 109 | + child: TextField( |
| 110 | + decoration: InputDecoration( |
| 111 | + border: OutlineInputBorder(), |
| 112 | + labelText: 'Sample Input', |
| 113 | + ), |
| 114 | + )), |
| 115 | + ), |
| 116 | + ], |
| 117 | +); |
0 commit comments