1 year ago
#329194
bensmith87
Flutter Navigate to Screen After User Clicks Link in Email Confirmation
I am attempting to Navigate to a screen based on an API response. When a user register's I have an API that sends a confirmation email with a link the user must click to verify their account / email. I am wanting to have my flutter app navigate to the user Dashboard screen after the user has clicked the link in the email to verify their account which will return status code 200.
I am having trouble figuring out how to do this in flutter.
Here is my code:
class EmailVerification extends StatefulWidget {
const EmailVerification({Key? key}) : super(key: key);
@override
State<EmailVerification> createState() => _EmailVerificationState();
}
class _EmailVerificationState extends State<EmailVerification> {
Future verifyEmail() async {
var response = await userEmailVerification(Provider.of<UserData>(context, listen: false).user.userID);
await emailVerified(response);
}
Future emailVerified(dynamic response) async {
if (response.statusCode == 200) {
setState(() {
Navigator.pushNamed(context, kRegistrationTOC);
});
}
print('Test');
}
@override
void initState() {
verifyEmail();
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<UserData>(
builder: (context, user, child) {
return WillPopScope(
onWillPop: () async {
return false;
},
child: Scaffold(
backgroundColor: eBackgroundColor,
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Image(
height: 100.0,
image: AssetImage(
'images/some_image.png'
),
),
),
WidgetSpacer(
height: 20.0,
),
Text(
'An email has been sent to: ${user.user.email}. Click the link to verify your email address.',
style: GoogleFonts.raleway(
fontSize: 25.0,
color: Colors.white,
fontWeight: FontWeight.bold,
letterSpacing: 1.0
),
),
WidgetSpacer(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Didn\'t receive an email?',
style: GoogleFonts.openSans(
color: Colors.white,
),
),
TextButton(
onPressed: () {
Navigator.pushNamed(context, kUserRegistrationID);
},
child: Text(
'Send again',
style: GoogleFonts.openSans(
color: Color(0xFF4A8082),
fontWeight: FontWeight.bold,
),
),
)
],
),
Padding(
padding: const EdgeInsets.only(
top: 15.0, left: 50.0, right: 50.0, bottom: 5.0),
child: Container(
width: double.infinity,
height: 35.0,
child: MaterialButton(
onPressed: () {
},
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0)
),
elevation: 10.0,
color: const Color(0xFFF7B666),
child: Text(
'Submit',
style: GoogleFonts.openSans(
fontSize: 25.0
),
),
),
),
),
],
),
),
),
),
);
}
);
}
}
flutter
api
async-await
navigator
0 Answers
Your Answer