Hello Flutter Developers. I have this issue which I need help with. I have created a sign up function in my code and I want it to be that when a user hit the sign up button it routes to the confirmation screen. Here's how the function is...
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),
);
}
}
and this is how the sign up button looks
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,
),
),
),
),
Anyone please help me I'd really appreciate it
CodePudding user response:
create that confirmation screen (ConfirmationPage) and then in your button function after setState, just call this:
Navigator.push(context, new MaterialPageRoute( builder: (context) => new ConfirmationPage()) );
CodePudding user response:
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,
),
),
),
),
And after setState(),add this line:
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => profile_page()
)