好的,因此在身份验证成功后(身份验证状态已更改)应触发流构建器导航到主页,但在运行期间,即使身份验证成功后,应用程序仍停留在登录屏幕上 我不确定该怎么办,应该尝试以某种方式使用Navigator.push()吗?还是有语法错误?实际上对我来说很好,尽管我可能是错的
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:memoii_book/Screens/feed_screen.dart';
import 'package:memoii_book/Screens/home_screen.dart';
import 'package:memoii_book/Screens/login_Screen.dart';
import 'package:memoii_book/Screens/signup_Screen.dart.';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
void state() {}
Widget getScreenId() {
return StreamBuilder<FirebaseUser>(
stream: FirebaseAuth.instance.onAuthStateChanged,
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
print('y');
return HomeScreen();
} else {
print('yo');
return loginScreen();
}
},
);
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MemoiiBook',
debugShowCheckedModeBanner: false,
home: getScreenId(),
routes: {
loginScreen.id: (context) => loginScreen(),
SignupScreen.id: (context) => SignupScreen(),
FeedScreen.id: (context) => FeedScreen(),
},
);
}
}
static void login(String email, String password) async
{
try{
await auth.signInWithEmailAndPassword(email: email, password: password);
final FirebaseUser currentUser = await auth.currentUser();
if (FirebaseAuth.instance.currentUser() != null) {
// signed in
} else {
}
}
catch(e)
{
print(e);
}
}