点击注册按钮后转到另一个屏幕



你好,Flutter开发人员。我有这个问题需要帮助。我在代码中创建了一个注册功能,我希望当用户点击注册按钮时,它会转到确认屏幕。以下是功能…

Future<void> signIn() async {
try {
final userAttribute = <CognitoUserAttributeKey, String>{
CognitoUserAttributeKey.email: _emailController.text,
};
final res = await Amplify.Auth.signUp(
username: _usernameController.text,
password: _passwordController.text,
options: CognitoSignUpOptions(userAttributes: userAttribute),
);
setState(() {
isSignedIn = res.isSignUpComplete;
});
} on AuthException catch (e) {
SnackBar(
content: Text('$e', style: const TextStyle(color: Colors.black)),
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.white,
elevation: 16.0,
margin: const EdgeInsets.all(8.0),
);
}
}

这就是注册按钮的样子

Container(
height: 40.0,
width: 140.0,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(7.0),
),
child: TextButton(
onPressed: signIn,
child: Text(
'Sign In',
style: GoogleFonts.frijole(
color: Colors.black,
),
),
),
),

任何人请帮帮我,我真的很感激

Container(
height: 40.0,
width: 140.0,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(7.0),
),
child: TextButton(
onPressed:    showPlatformDialog(
context: this.context,
builder: (context) => BasicDialogAlert(
title: Text("Are you sure?"),
actions: <Widget>[
BasicDialogAction(
title: Text("cancel"),
onPressed: () {
Navigator.pop(context);
},
),
BasicDialogAction(
title: Text("ok"),
onPressed: () {
signIn();
},
),
],
),
),
child: Text(
'Sign In',
style: GoogleFonts.frijole(
color: Colors.black,
),
),
),
),

setState((之后,添加此行:

Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => profile_page()
)

最新更新