@@ -14,9 +14,34 @@ class _MainAppState extends State<MainApp> {
14
14
@override
15
15
void initState () {
16
16
super .initState ();
17
- Store .setStoreCtx (context);
17
+ Store .setStoreCtx (context);// 初始化数据层
18
18
}
19
19
20
+ @override
21
+ Widget build (BuildContext context) {
22
+ Store .value <UserModel >(context).getLocalUserInfo ();
23
+ return Store .connect <UserModel >(
24
+ builder: (context, child, model) {
25
+ return MaterialApp (
26
+ title: 'Flutter Demo' ,
27
+ theme: ThemeData (
28
+ primarySwatch: Colors .blue,
29
+ ),
30
+ home: HomePage (),
31
+ );
32
+ }
33
+ );
34
+ }
35
+ }
36
+
37
+
38
+ class HomePage extends StatefulWidget {
39
+ @override
40
+ _HomePageState createState () => _HomePageState ();
41
+ }
42
+
43
+ class _HomePageState extends State <HomePage > {
44
+
20
45
// 抽屉面板
21
46
renderDrawer () {
22
47
return Drawer (
@@ -88,52 +113,46 @@ class _MainAppState extends State<MainApp> {
88
113
89
114
@override
90
115
Widget build (BuildContext context) {
91
- Store .value < UserModel > (context). getLocalUserInfo ();
116
+ Store .setWidgetCtx (context); // 初始化scaffold的上下文作为全局上下文,提供弹框等使用
92
117
return Store .connect <UserModel >(
93
118
builder: (context, child, model) {
94
- return MaterialApp (
95
- title: 'Flutter Demo' ,
96
- theme: ThemeData (
97
- primarySwatch: Colors .blue,
119
+ return Scaffold (
120
+ appBar: AppBar (
121
+ title: Text ('Flutter UI 接入github登陆' ),
98
122
),
99
- home: Scaffold (
100
- appBar: AppBar (
101
- title: Text ('Flutter UI 接入github登陆' ),
102
- ),
103
- body: Center (
104
- child: Column (
105
- mainAxisAlignment: MainAxisAlignment .center,
106
- children: < Widget > [
107
- model.showLogin ?
108
- AppLogin ()
109
- :
110
- ListTile (
111
- leading: ClipOval (
112
- child: model.user.avatar_url != null
113
- ? Image .network (
114
- model.user.avatar_url,
115
- width: 80 ,
116
- )
117
- : Icon (Icons .account_box),
118
- ),
119
- title: Text (
120
- model.user.name ?? 'Guest' ,
121
- style: TextStyle (fontWeight: FontWeight .bold)
122
- ),
123
- onTap: () {
124
- // Scaffold.of(context).openDrawer()
125
- if (model.user.avatar_url == null ) {
126
- model.changeShowLogin (true );
127
- }
123
+ body: Center (
124
+ child: Column (
125
+ mainAxisAlignment: MainAxisAlignment .center,
126
+ children: < Widget > [
127
+ model.showLogin ?
128
+ AppLogin ()
129
+ :
130
+ ListTile (
131
+ leading: ClipOval (
132
+ child: model.user.avatar_url != null
133
+ ? Image .network (
134
+ model.user.avatar_url,
135
+ width: 80 ,
136
+ )
137
+ : Icon (Icons .account_box),
138
+ ),
139
+ title: Text (
140
+ model.user.name ?? 'Guest' ,
141
+ style: TextStyle (fontWeight: FontWeight .bold)
142
+ ),
143
+ onTap: () {
144
+ // Scaffold.of(context).openDrawer()
145
+ if (model.user.avatar_url == null ) {
146
+ model.changeShowLogin (true );
128
147
}
129
- )
130
- ],
131
- ) ,
148
+ }
149
+ )
150
+ ] ,
132
151
),
133
- drawer: renderDrawer (),
134
152
),
153
+ drawer: renderDrawer (),
135
154
);
136
155
}
137
156
);
138
157
}
139
- }
158
+ }
0 commit comments