add structure
This commit is contained in:
368
lib/pages/reset_password.dart
Normal file
368
lib/pages/reset_password.dart
Normal file
@@ -0,0 +1,368 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/user_model.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import '../theme/theme.dart' as Theme;
|
||||
import 'util.dart';
|
||||
|
||||
class ResetPasswordPage extends StatefulWidget {
|
||||
final String phoneNumber;
|
||||
ResetPasswordPage(
|
||||
this.phoneNumber, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ResetPasswordPageState createState() => new _ResetPasswordPageState();
|
||||
}
|
||||
|
||||
class _ResetPasswordPageState extends State<ResetPasswordPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
final FocusNode myFocusNodePassword = FocusNode();
|
||||
final FocusNode myFocusNodeEmail = FocusNode();
|
||||
|
||||
bool _obscureTextLogin = true;
|
||||
bool _obscureTextSignup = true;
|
||||
bool _obscureTextSignupConfirm = true;
|
||||
|
||||
TextEditingController _smsController = new TextEditingController();
|
||||
TextEditingController _passwordController = new TextEditingController();
|
||||
TextEditingController _confirmPasswordController =
|
||||
new TextEditingController();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
key: _scaffoldKey,
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height >= 775.0
|
||||
? MediaQuery.of(context).size.height
|
||||
: 580.0,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 35.0, bottom: 10),
|
||||
child: ListTile(
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
title: LocalText(
|
||||
context,
|
||||
'reset.password.title',
|
||||
color: Colors.black87,
|
||||
fontSize: 17,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PageView(
|
||||
children: <Widget>[
|
||||
new ConstrainedBox(
|
||||
constraints: const BoxConstraints.expand(),
|
||||
child: _buildReset(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
myFocusNodePassword.dispose();
|
||||
myFocusNodeEmail.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// SystemChrome.setPreferredOrientations([
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
|
||||
_smsController.text = "";
|
||||
}
|
||||
|
||||
Widget _buildReset(BuildContext context) {
|
||||
return Container(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Form(
|
||||
key: formKey,
|
||||
child: Card(
|
||||
elevation: 2.0,
|
||||
color: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: Container(
|
||||
width: 300.0,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 25.0, right: 25.0),
|
||||
child: TextFormField(
|
||||
focusNode: myFocusNodeEmail,
|
||||
controller: _smsController,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.sms,
|
||||
color: Colors.black,
|
||||
),
|
||||
labelText: AppTranslations.of(context)
|
||||
.text("reset.sms"),
|
||||
labelStyle:
|
||||
Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
color: Colors.grey)
|
||||
: TextStyle(
|
||||
fontFamily: "MyanmarUnicode",
|
||||
color: Colors.grey),
|
||||
),
|
||||
validator: _validateSMSCode),
|
||||
),
|
||||
Container(
|
||||
width: 250.0,
|
||||
height: 1.0,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 25.0, right: 25.0),
|
||||
child: TextFormField(
|
||||
focusNode: myFocusNodePassword,
|
||||
controller: _passwordController,
|
||||
obscureText: _obscureTextSignup,
|
||||
style: TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.lock,
|
||||
color: Colors.black,
|
||||
),
|
||||
labelText: AppTranslations.of(context)
|
||||
.text("reset.new_password"),
|
||||
labelStyle:
|
||||
Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
color: Colors.grey)
|
||||
: TextStyle(
|
||||
fontFamily: "MyanmarUnicode",
|
||||
color: Colors.grey),
|
||||
suffixIcon: GestureDetector(
|
||||
onTap: _toggleSignup,
|
||||
child: Icon(
|
||||
_obscureTextSignup
|
||||
? FontAwesomeIcons.eye
|
||||
: FontAwesomeIcons.eyeSlash,
|
||||
size: 15.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
validator: _validatePassword,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 250.0,
|
||||
height: 1.0,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 25.0, right: 25.0),
|
||||
child: TextFormField(
|
||||
controller: _confirmPasswordController,
|
||||
obscureText: _obscureTextSignupConfirm,
|
||||
style: TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.lock,
|
||||
color: Colors.black,
|
||||
),
|
||||
labelText: AppTranslations.of(context)
|
||||
.text("login.confirm_password"),
|
||||
labelStyle:
|
||||
Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(
|
||||
fontFamily: "WorkSansSemiBold",
|
||||
color: Colors.grey)
|
||||
: TextStyle(
|
||||
fontFamily: "MyanmarUnicode",
|
||||
color: Colors.grey),
|
||||
suffixIcon: GestureDetector(
|
||||
onTap: _toggleSignupConfirm,
|
||||
child: Icon(
|
||||
_obscureTextSignupConfirm
|
||||
? FontAwesomeIcons.eye
|
||||
: FontAwesomeIcons.eyeSlash,
|
||||
size: 15.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
validator: _validateConfirmPassword,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
// margin: EdgeInsets.only(top: 320.0),
|
||||
decoration: new BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
color: Theme.primaryColor,
|
||||
),
|
||||
child: MaterialButton(
|
||||
highlightColor: Colors.transparent,
|
||||
splashColor: Theme.LoginColors.loginGradientEnd,
|
||||
//shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5.0))),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10.0, horizontal: 42.0),
|
||||
child: Text(
|
||||
AppTranslations.of(context).text("reset"),
|
||||
style: Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18.0,
|
||||
fontFamily: "WorkSansBold")
|
||||
: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18.0,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
),
|
||||
onPressed: () => _reset(context)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleLogin() {
|
||||
setState(() {
|
||||
_obscureTextLogin = !_obscureTextLogin;
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleSignup() {
|
||||
setState(() {
|
||||
_obscureTextSignup = !_obscureTextSignup;
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleSignupConfirm() {
|
||||
setState(() {
|
||||
_obscureTextSignupConfirm = !_obscureTextSignupConfirm;
|
||||
});
|
||||
}
|
||||
|
||||
void _reset(BuildContext context) async {
|
||||
if (!formKey.currentState.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var smsCode = _smsController.text;
|
||||
var password = _passwordController.text;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
UserModel userModel = Provider.of<UserModel>(context);
|
||||
try {
|
||||
await userModel.resetPassword(widget.phoneNumber, password, smsCode);
|
||||
Navigator.pushNamedAndRemoveUntil(context, "/login", (r) => false);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
Future.delayed(Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String _validatePassword(value) {
|
||||
if (value.isEmpty) {
|
||||
return AppTranslations.of(context).text("login.password_empty");
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return AppTranslations.of(context).text("login.password_size");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _validateConfirmPassword(value) {
|
||||
if (value.isEmpty) {
|
||||
return AppTranslations.of(context).text("login.confirm_password_empty");
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return AppTranslations.of(context).text("login.password_size");
|
||||
}
|
||||
if (value != _passwordController.text) {
|
||||
return AppTranslations.of(context).text("login.password_mismatch");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _validateSMSCode(value) {
|
||||
if (value.isEmpty) {
|
||||
return AppTranslations.of(context).text("login.sms_empty");
|
||||
}
|
||||
if (value.length != 6) {
|
||||
return AppTranslations.of(context).text("login.sms_size");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user