2020-05-29 07:45:27 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:progress/progress.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:fcs/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/model/user_model.dart';
|
|
|
|
|
import 'package:fcs/pages/reset_password.dart';
|
2020-09-04 15:30:10 +06:30
|
|
|
import 'package:fcs/fcs/common/helpers/theme.dart';
|
2020-05-29 07:45:27 +06:30
|
|
|
import 'package:fcs/widget/local_text.dart';
|
|
|
|
|
import 'package:fcs/widget/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
|
|
2020-09-04 15:30:10 +06:30
|
|
|
import '../fcs/common/pages/util.dart';
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
class ForgetPassword extends StatefulWidget {
|
|
|
|
|
final phoneNumber;
|
|
|
|
|
|
|
|
|
|
const ForgetPassword({Key key, this.phoneNumber}) : super(key: key);
|
|
|
|
|
@override
|
|
|
|
|
_ForgetPasswordState createState() => _ForgetPasswordState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ForgetPasswordState extends State<ForgetPassword> {
|
|
|
|
|
final TextEditingController _email = new TextEditingController();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_email.text = widget.phoneNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final emailInput = TextFormField(
|
|
|
|
|
controller: _email,
|
|
|
|
|
autofocus: false,
|
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
|
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
|
|
|
|
|
labelText: AppTranslations.of(context).text("forget.email"),
|
|
|
|
|
labelStyle: labelStyle,
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.email,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
)),
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
return AppTranslations.of(context).text("forget.email.empty");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final enterButton = Padding(
|
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
|
|
|
child: RaisedButton(
|
|
|
|
|
onPressed: () => _forgetPassword(),
|
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(7),
|
|
|
|
|
),
|
|
|
|
|
child: Text(AppTranslations.of(context).text("forget.enter"),
|
|
|
|
|
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'forget.password',
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
body: Center(
|
|
|
|
|
child: ListView(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Form(key: _formKey, child: emailInput),
|
|
|
|
|
SizedBox(height: 8.0),
|
|
|
|
|
enterButton,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _forgetPassword() async {
|
|
|
|
|
var phoneNumber = _email.text;
|
|
|
|
|
if (phoneNumber.isEmpty) {
|
|
|
|
|
showMsgDialog(context, "Error", "Please input email(or)phone number");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
UserModel userModel = Provider.of<UserModel>(context);
|
|
|
|
|
await userModel.forgetPassword(phoneNumber);
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => ResetPasswordPage(phoneNumber)));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|