|
| 1 | +import 'dart:convert'; |
| 2 | + |
| 3 | +import 'package:blogapp/Pages/HomePage.dart'; |
| 4 | +import 'package:blogapp/Pages/SignUpPage.dart'; |
| 5 | +import 'package:blogapp/Pages/WelcomePage.dart'; |
| 6 | +import "package:flutter/material.dart"; |
| 7 | + |
| 8 | +import '../NetworkHandler.dart'; |
| 9 | +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; |
| 10 | + |
| 11 | +class ForgotPasswordPage extends StatefulWidget { |
| 12 | + ForgotPasswordPage({Key key}) : super(key: key); |
| 13 | + |
| 14 | + @override |
| 15 | + _ForgotPasswordPageState createState() => _ForgotPasswordPageState(); |
| 16 | +} |
| 17 | + |
| 18 | +class _ForgotPasswordPageState extends State<ForgotPasswordPage> { |
| 19 | + bool vis = true; |
| 20 | + final _globalkey = GlobalKey<FormState>(); |
| 21 | + NetworkHandler networkHandler = NetworkHandler(); |
| 22 | + TextEditingController _usernameController = TextEditingController(); |
| 23 | + TextEditingController _passwordController = TextEditingController(); |
| 24 | + String errorText; |
| 25 | + bool validate = false; |
| 26 | + bool circular = false; |
| 27 | + final storage = new FlutterSecureStorage(); |
| 28 | + @override |
| 29 | + Widget build(BuildContext context) { |
| 30 | + return Scaffold( |
| 31 | + body: Container( |
| 32 | + // height: MediaQuery.of(context).size.height, |
| 33 | + // width: MediaQuery.of(context).size.width, |
| 34 | + decoration: BoxDecoration( |
| 35 | + gradient: LinearGradient( |
| 36 | + colors: [Colors.white, Colors.green[200]], |
| 37 | + begin: const FractionalOffset(0.0, 1.0), |
| 38 | + end: const FractionalOffset(0.0, 1.0), |
| 39 | + stops: [0.0, 1.0], |
| 40 | + tileMode: TileMode.repeated, |
| 41 | + ), |
| 42 | + ), |
| 43 | + child: Form( |
| 44 | + key: _globalkey, |
| 45 | + child: Padding( |
| 46 | + padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10.0), |
| 47 | + child: Column( |
| 48 | + mainAxisAlignment: MainAxisAlignment.center, |
| 49 | + children: [ |
| 50 | + Text( |
| 51 | + "Forgot Password", |
| 52 | + style: TextStyle( |
| 53 | + fontSize: 30, |
| 54 | + fontWeight: FontWeight.bold, |
| 55 | + letterSpacing: 2, |
| 56 | + ), |
| 57 | + ), |
| 58 | + SizedBox( |
| 59 | + height: 20, |
| 60 | + ), |
| 61 | + usernameTextField(), |
| 62 | + SizedBox( |
| 63 | + height: 15, |
| 64 | + ), |
| 65 | + passwordTextField(), |
| 66 | + SizedBox( |
| 67 | + height: 20, |
| 68 | + ), |
| 69 | + |
| 70 | + SizedBox( |
| 71 | + height: 30, |
| 72 | + ), |
| 73 | + InkWell( |
| 74 | + onTap: () async { |
| 75 | + Map<String, String> data = { |
| 76 | + "password": _passwordController.text |
| 77 | + }; |
| 78 | + print("/user/update/${_usernameController.text}"); |
| 79 | + var response = await networkHandler.patch( |
| 80 | + "/user/update/${_usernameController.text}", data); |
| 81 | + |
| 82 | + if (response.statusCode == 200 || |
| 83 | + response.statusCode == 201) { |
| 84 | + print("/user/update/${_usernameController.text}"); |
| 85 | + Navigator.pushAndRemoveUntil( |
| 86 | + context, |
| 87 | + MaterialPageRoute( |
| 88 | + builder: (context) => WelcomePage()), |
| 89 | + (route) => false); |
| 90 | + } |
| 91 | + |
| 92 | + // login logic End here |
| 93 | + }, |
| 94 | + child: Container( |
| 95 | + width: 150, |
| 96 | + height: 50, |
| 97 | + decoration: BoxDecoration( |
| 98 | + borderRadius: BorderRadius.circular(10), |
| 99 | + color: Color(0xff00A86B), |
| 100 | + ), |
| 101 | + child: Center( |
| 102 | + child: circular |
| 103 | + ? CircularProgressIndicator() |
| 104 | + : Text( |
| 105 | + "Update Password", |
| 106 | + style: TextStyle( |
| 107 | + color: Colors.white, |
| 108 | + fontSize: 15, |
| 109 | + fontWeight: FontWeight.bold, |
| 110 | + ), |
| 111 | + ), |
| 112 | + ), |
| 113 | + ), |
| 114 | + ), |
| 115 | + // Divider( |
| 116 | + // height: 50, |
| 117 | + // thickness: 1.5, |
| 118 | + // ), |
| 119 | + ], |
| 120 | + ), |
| 121 | + ), |
| 122 | + ), |
| 123 | + ), |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + Widget usernameTextField() { |
| 128 | + return Column( |
| 129 | + children: [ |
| 130 | + Text("Username"), |
| 131 | + TextFormField( |
| 132 | + controller: _usernameController, |
| 133 | + decoration: InputDecoration( |
| 134 | + errorText: validate ? null : errorText, |
| 135 | + focusedBorder: UnderlineInputBorder( |
| 136 | + borderSide: BorderSide( |
| 137 | + color: Colors.black, |
| 138 | + width: 2, |
| 139 | + ), |
| 140 | + ), |
| 141 | + ), |
| 142 | + ) |
| 143 | + ], |
| 144 | + ); |
| 145 | + } |
| 146 | + |
| 147 | + Widget passwordTextField() { |
| 148 | + return Column( |
| 149 | + children: [ |
| 150 | + Text("Password"), |
| 151 | + TextFormField( |
| 152 | + controller: _passwordController, |
| 153 | + obscureText: vis, |
| 154 | + decoration: InputDecoration( |
| 155 | + errorText: validate ? null : errorText, |
| 156 | + suffixIcon: IconButton( |
| 157 | + icon: Icon(vis ? Icons.visibility_off : Icons.visibility), |
| 158 | + onPressed: () { |
| 159 | + setState(() { |
| 160 | + vis = !vis; |
| 161 | + }); |
| 162 | + }, |
| 163 | + ), |
| 164 | + helperStyle: TextStyle( |
| 165 | + fontSize: 14, |
| 166 | + ), |
| 167 | + focusedBorder: UnderlineInputBorder( |
| 168 | + borderSide: BorderSide( |
| 169 | + color: Colors.black, |
| 170 | + width: 2, |
| 171 | + ), |
| 172 | + ), |
| 173 | + ), |
| 174 | + ) |
| 175 | + ], |
| 176 | + ); |
| 177 | + } |
| 178 | +} |
0 commit comments