【发布时间】:2021-01-16 15:44:47
【问题描述】:
我正在尝试实现course in AWS 以在 Flutter 中连接 Amplify。但是在“创建身份验证流程”中,当它在pages 中添加MaterialPage 时,在Navigator 中找不到它。
我在MaterialPage 中有这个错误:
没有为类型“_MyAuthStateState”定义方法“MaterialPage”。尝试将名称更正为现有方法的名称,或定义名为“MaterialPage”的方法。
我当前的代码(main.dart):
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _authService = AuthService();
@override
void initState() {
super.initState();
_authService.showLogin();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Photo Gallery App',
theme: ThemeData(visualDensity: VisualDensity.adaptivePlatformDensity),
home: StreamBuilder<AuthState>(
// 2
stream: _authService.authStateController.stream,
builder: (context, snapshot) {
// 3
if (snapshot.hasData) {
return Navigator(
pages: [
// 4
// Show Login Page
if (snapshot.data.authFlowStatus == AuthFlowStatus.login)
MaterialPage(
child: LoginPage(
shouldShowSignUp: _authService.showSignUp,
didProvideCredentials:
_authService.loginWithCredentials,
),
),
// 5
// Show Sign Up Page
if (snapshot.data.authFlowStatus == AuthFlowStatus.signUp)
MaterialPage(
child: SignUpPage(
shouldShowLogin: _authService.showLogin,
didProvideCredentials: _authService.signUpWithCredentials,
)),
if (snapshot.data.authFlowStatus ==
AuthFlowStatus.verification)
MaterialPage(
child: VerificationPage(
didProvideVerificationCode:
_authService.verifyCode))
],
onPopPage: (route, result) => route.didPop(result),
);
} else {
// 6
return Container(
alignment: Alignment.center,
child: CircularProgressIndicator(),
);
}
}),
);
}
}
【问题讨论】:
标签: amazon-web-services flutter aws-amplify