質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,11 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
自分なりにいくつか調べ、それらを試したのですが
|
13
|
+
自分なりにいくつか調べ、それらを試したのですがそもそもログインページに遷移しませんでした。
|
14
|
+
|
15
|
+
試したコードは以下mainコードです。
|
16
|
+
|
17
|
+
|
14
18
|
|
15
19
|
具体的な方法としてどのように行うことで以上の機能を実装することができるのでしょうか?
|
16
20
|
|
@@ -56,44 +60,150 @@
|
|
56
60
|
|
57
61
|
|
58
62
|
|
59
|
-
```
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
e
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
63
|
+
```main
|
64
|
+
|
65
|
+
class MyApp extends StatelessWidget {
|
66
|
+
|
67
|
+
// This widget is the root of your application.
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
final UserState user = UserState();
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
@override
|
76
|
+
|
77
|
+
Widget build(BuildContext context) {
|
78
|
+
|
79
|
+
return ChangeNotifierProvider<UserState>.value(
|
80
|
+
|
81
|
+
value: user,
|
82
|
+
|
83
|
+
child: MaterialApp(
|
84
|
+
|
85
|
+
//デバックラベル非表示
|
86
|
+
|
87
|
+
debugShowCheckedModeBanner: false,
|
88
|
+
|
89
|
+
title: 'Flutter Demo',
|
90
|
+
|
91
|
+
theme: ThemeData(
|
92
|
+
|
93
|
+
primarySwatch: Colors.blue,
|
94
|
+
|
95
|
+
visualDensity: VisualDensity.adaptivePlatformDensity,
|
96
|
+
|
97
|
+
),
|
98
|
+
|
99
|
+
home: LoginPage(),
|
100
|
+
|
101
|
+
initialRoute: "/",
|
102
|
+
|
103
|
+
routes:<String, WidgetBuilder>{
|
104
|
+
|
105
|
+
// "/": (BuildContext context) => LoginPage(),
|
106
|
+
|
107
|
+
AddRecord.routeName: (BuildContext context) => AddRecord(),
|
108
|
+
|
109
|
+
"/login":(BuildContext context) => LoginPage(),
|
110
|
+
|
111
|
+
"/home":(BuildContext context) => PageManager()
|
112
|
+
|
113
|
+
},
|
114
|
+
|
115
|
+
)
|
116
|
+
|
117
|
+
);
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class LoginCheck extends StatefulWidget{
|
126
|
+
|
127
|
+
LoginCheck({Key key}) : super(key: key);
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
@override
|
132
|
+
|
133
|
+
_LoginCheckState createState() => _LoginCheckState();
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
class _LoginCheckState extends State<LoginCheck>{
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
@override
|
146
|
+
|
147
|
+
void initState(){
|
148
|
+
|
149
|
+
super.initState();
|
150
|
+
|
151
|
+
checkUser();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// TODO: implement initState
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
void checkUser() async{
|
164
|
+
|
165
|
+
final UserState userState = Provider.of<UserState>(context);
|
166
|
+
|
167
|
+
final currentUser = await FirebaseAuth.instance.currentUser();
|
168
|
+
|
169
|
+
print(currentUser);
|
170
|
+
|
171
|
+
if(currentUser == null){
|
172
|
+
|
173
|
+
Navigator.pushReplacementNamed(context,"/login");
|
174
|
+
|
175
|
+
}else{
|
176
|
+
|
177
|
+
userState.setUser(currentUser);
|
178
|
+
|
179
|
+
Navigator.pushReplacementNamed(context, "/home");
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
@override
|
186
|
+
|
187
|
+
Widget build(BuildContext context) {
|
188
|
+
|
189
|
+
// TODO: implement build
|
190
|
+
|
191
|
+
return Scaffold(
|
192
|
+
|
193
|
+
body: Center(
|
194
|
+
|
195
|
+
child: Container(
|
196
|
+
|
197
|
+
child: Text("Loading..."),
|
198
|
+
|
199
|
+
),
|
200
|
+
|
201
|
+
),
|
202
|
+
|
203
|
+
);
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
98
208
|
|
99
209
|
```
|