|
@@ -8,35 +8,17 @@ class MyApp extends StatelessWidget {
|
8
|
8
|
@override
|
9
|
9
|
Widget build(BuildContext context) {
|
10
|
10
|
return new MaterialApp(
|
11
|
|
- title: 'Flutter Demo',
|
|
11
|
+ title: 'Pick Image Demo',
|
12
|
12
|
theme: new ThemeData(
|
13
|
|
- // This is the theme of your application.
|
14
|
|
- //
|
15
|
|
- // Try running your application with "flutter run". You'll see the
|
16
|
|
- // application has a blue toolbar. Then, without quitting the app, try
|
17
|
|
- // changing the primarySwatch below to Colors.green and then invoke
|
18
|
|
- // "hot reload" (press "r" in the console where you ran "flutter run",
|
19
|
|
- // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
|
20
|
|
- // counter didn't reset back to zero; the application is not restarted.
|
21
|
13
|
primarySwatch: Colors.blue,
|
22
|
14
|
),
|
23
|
|
- home: new MyHomePage(title: 'Flutter Demo Home Page'),
|
|
15
|
+ home: new MyHomePage(title: 'Pick Image Demo'),
|
24
|
16
|
);
|
25
|
17
|
}
|
26
|
18
|
}
|
27
|
19
|
|
28
|
20
|
class MyHomePage extends StatefulWidget {
|
29
|
21
|
MyHomePage({Key key, this.title}) : super(key: key);
|
30
|
|
-
|
31
|
|
- // This widget is the home page of your application. It is stateful, meaning
|
32
|
|
- // that it has a State object (defined below) that contains fields that affect
|
33
|
|
- // how it looks.
|
34
|
|
-
|
35
|
|
- // This class is the configuration for the state. It holds the values (in this
|
36
|
|
- // case the title) provided by the parent (in this case the App widget) and
|
37
|
|
- // used by the build method of the State. Fields in a Widget subclass are
|
38
|
|
- // always marked "final".
|
39
|
|
-
|
40
|
22
|
final String title;
|
41
|
23
|
|
42
|
24
|
@override
|
|
@@ -44,9 +26,8 @@ class MyHomePage extends StatefulWidget {
|
44
|
26
|
}
|
45
|
27
|
|
46
|
28
|
class _MyHomePageState extends State<MyHomePage> {
|
47
|
|
- int _counter = 0;
|
48
|
29
|
|
49
|
|
- void _incrementCounter() async{
|
|
30
|
+ void _pickImage() async{
|
50
|
31
|
var imgList = await PhotoPicker.pickImage(
|
51
|
32
|
context: context,
|
52
|
33
|
themeColor: Colors.green,
|
|
@@ -61,52 +42,16 @@ class _MyHomePageState extends State<MyHomePage> {
|
61
|
42
|
|
62
|
43
|
@override
|
63
|
44
|
Widget build(BuildContext context) {
|
64
|
|
- // This method is rerun every time setState is called, for instance as done
|
65
|
|
- // by the _incrementCounter method above.
|
66
|
|
- //
|
67
|
|
- // The Flutter framework has been optimized to make rerunning build methods
|
68
|
|
- // fast, so that you can just rebuild anything that needs updating rather
|
69
|
|
- // than having to individually change instances of widgets.
|
70
|
45
|
return new Scaffold(
|
71
|
46
|
appBar: new AppBar(
|
72
|
|
- // Here we take the value from the MyHomePage object that was created by
|
73
|
|
- // the App.build method, and use it to set our appbar title.
|
74
|
47
|
title: new Text(widget.title),
|
75
|
48
|
),
|
76
|
|
- body: new Center(
|
77
|
|
- // Center is a layout widget. It takes a single child and positions it
|
78
|
|
- // in the middle of the parent.
|
79
|
|
- child: new Column(
|
80
|
|
- // Column is also layout widget. It takes a list of children and
|
81
|
|
- // arranges them vertically. By default, it sizes itself to fit its
|
82
|
|
- // children horizontally, and tries to be as tall as its parent.
|
83
|
|
- //
|
84
|
|
- // Invoke "debug paint" (press "p" in the console where you ran
|
85
|
|
- // "flutter run", or select "Toggle Debug Paint" from the Flutter tool
|
86
|
|
- // window in IntelliJ) to see the wireframe for each widget.
|
87
|
|
- //
|
88
|
|
- // Column has various properties to control how it sizes itself and
|
89
|
|
- // how it positions its children. Here we use mainAxisAlignment to
|
90
|
|
- // center the children vertically; the main axis here is the vertical
|
91
|
|
- // axis because Columns are vertical (the cross axis would be
|
92
|
|
- // horizontal).
|
93
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
94
|
|
- children: <Widget>[
|
95
|
|
- new Text(
|
96
|
|
- 'You have pushed the button this many times:',
|
97
|
|
- ),
|
98
|
|
- new Text(
|
99
|
|
- '$_counter',
|
100
|
|
- style: Theme.of(context).textTheme.display1,
|
101
|
|
- ),
|
102
|
|
- ],
|
103
|
|
- ),
|
104
|
|
- ),
|
|
49
|
+ body: Container(),
|
105
|
50
|
floatingActionButton: new FloatingActionButton(
|
106
|
|
- onPressed: _incrementCounter,
|
107
|
|
- tooltip: 'Increment',
|
|
51
|
+ onPressed: _pickImage,
|
|
52
|
+ tooltip: 'pickImage',
|
108
|
53
|
child: new Icon(Icons.add),
|
109
|
|
- ), // This trailing comma makes auto-formatting nicer for build methods.
|
|
54
|
+ ),
|
110
|
55
|
);
|
111
|
56
|
}
|
112
|
57
|
|