Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:firebase_auth/firebase_auth.dart';
- import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import './login.dart';
- final FirebaseAuth _auth = FirebaseAuth.instance;
- class ForgotPass extends StatefulWidget {
- @override
- ForgotPassState createState() => ForgotPassState();
- }
- class ForgotPassState extends State<ForgotPass> with WidgetsBindingObserver {
- final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
- final TextEditingController _emailController = TextEditingController();
- final TextEditingController _passwordController = TextEditingController();
- bool _success;
- String _userEmail;
- String val;
- String _userID;
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance.addObserver(this);
- }
- @override
- Widget build(BuildContext context) {
- SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
- statusBarColor: Colors.yellow.shade800,
- ));
- return Stack(children: <Widget>[
- Container(color: Color(0xFF18181C)),
- Container(
- alignment: Alignment.topCenter,
- color: Color(0xFF232428),
- margin:
- const EdgeInsets.only(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0),
- child: new Image.asset('images/login2.png',
- width: 300.0, height: 248.0, alignment: Alignment.center),
- ),
- Container(
- alignment: Alignment.topCenter,
- color: Color(0xFF232428),
- margin: const EdgeInsets.only(
- left: 0.0, right: 0.0, top: 260.0, bottom: 0.0),
- child: new Image.asset('images/login_title_forgot.png',
- width: 49.0, height: 14.0, alignment: Alignment.center),
- ),
- Container(
- alignment: Alignment.topCenter,
- child: Form(
- key: _formKey,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- SystemChannels.textInput.invokeMethod('TextInput.hide');
- // FocusScope.of(context).requestFocus(new FocusNode());
- },
- child: Card(
- elevation: 0,
- margin: const EdgeInsets.only(
- top: 280.0, bottom: 0.0, right: 0.0, left: 0.0),
- child: Container(
- padding: const EdgeInsets.all(20.0),
- height: 243.0,
- width: 350.0,
- color: Color(0xFF232428),
- child: new Column(children: <Widget>[
- new TextFormField(
- controller: _emailController,
- cursorColor: Color(0xFFEDAC0B),
- validator: (String value) {
- if (value.isEmpty) {
- return 'Please Enter A Valid Email';
- }
- if (RegExp(r'(\w+@\w+\.\w+)')
- .stringMatch(val) !=
- val) return 'Please Enter A Valid E-Mail';
- },
- // onSaved: (input) => _email = input,
- style: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- keyboardType: TextInputType.emailAddress,
- decoration: new InputDecoration(
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0),
- borderSide: const BorderSide(
- color: Color(0xFFEDAC0B), width: 0.0),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0),
- borderSide: const BorderSide(
- color: Color(0xFFEDAC0B)),
- ),
- labelText: 'Email',
- labelStyle: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- hintStyle: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- prefixIcon: new Icon(Icons.email,
- color: Color(0xFFEDAC0B)),
- ),
- ),
- new Container(
- height: 8.0,
- ),
- new TextFormField(
- cursorColor: Color(0xFFEDAC0B),
- controller: _passwordController,
- validator: (String value) {
- if (value.isEmpty) {
- return 'Please Enter A Valid Password';
- }
- },
- // onSaved: (input) => _password = input,
- style: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- keyboardType: TextInputType.text,
- decoration: new InputDecoration(
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0),
- borderSide: const BorderSide(
- color: Color(0xFFEDAC0B), width: 0.0),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0),
- borderSide: const BorderSide(
- color: Color(0xFFEDAC0B)),
- ),
- labelText: 'Password',
- labelStyle: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- hintStyle: TextStyle(
- color: Color(0xFF606060),
- fontWeight: FontWeight.w300),
- prefixIcon: new Icon(Icons.lock,
- color: Color(0xFFEDAC0B)),
- suffixIcon: new Icon(Icons.visibility_off,
- color: Color(0xFF606060)),
- ),
- obscureText: true,
- ),
- ])))))),
- new Container(
- alignment: Alignment.bottomRight,
- margin: const EdgeInsets.only(
- left: 0.0, right: 30.0, top: 0.0, bottom: 48.0),
- child: GestureDetector(
- onTap: () {
- if (_formKey.currentState.validate()) {
- _signInWithEmailAndLink();
- }
- print("Back To Login Button Clicked");
- Navigator.pop(
- context,
- new MaterialPageRoute(
- maintainState: true, builder: (context) => new Login()));
- },
- //
- child: Image.asset(
- 'images/login_button_redarrow.png',
- width: 40.0,
- height: 40.0,
- ),
- )),
- new Container(
- alignment: Alignment.bottomCenter,
- margin: const EdgeInsets.only(
- left: 0.0, right: 00.0, top: 0.0, bottom: 10.0),
- child: new Image.asset(
- 'images/footer2.png',
- width: 123.0,
- height: 14.0,
- )),
- ]);
- }
- @override
- void dispose() {
- _emailController.dispose();
- WidgetsBinding.instance.removeObserver(this);
- super.dispose();
- }
- @override
- void didChangeAppLifecycleState(AppLifecycleState state) async {
- if (state == AppLifecycleState.resumed) {
- final Uri link = await _retrieveDynamicLink();
- if (link != null) {
- final FirebaseUser user = await _auth.signInWithEmailAndLink(
- email: _userEmail,
- link: link.toString(),
- );
- if (user != null) {
- _userID = user.uid;
- _success = true;
- } else {
- _success = false;
- }
- } else {
- _success = false;
- setState(() {});
- }
- }
- Future<Uri> _retrieveDynamicLink() async {
- final PendingDynamicLinkData data =
- await FirebaseDynamicLinks.instance.retrieveDynamicLink();
- return data?.link;
- }
- Future<void> _signInWithEmailAndLink() async {
- _userEmail = _emailController.text;
- return await _auth.sendSignInWithEmailLink(
- email: _userEmail,
- url: 'localhost',
- handleCodeInApp: true,
- iOSBundleID: 'io.flutter.plugins.firebaseAuthExample',
- androidPackageName: 'io.svgo.svgo',
- androidInstallIfNotAvailable: true,
- androidMinimumVersion: "1",
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement