2020-05-29 07:45:27 +06:30
|
|
|
import 'package:flutter/material.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/vo/user.dart';
|
|
|
|
|
import 'package:fcs/widget/local_text.dart';
|
|
|
|
|
import 'package:fcs/widget/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
|
|
2020-08-30 21:26:37 +06:30
|
|
|
import '../fcs/common/theme.dart' as Theme;
|
2020-05-29 07:45:27 +06:30
|
|
|
import 'util.dart';
|
|
|
|
|
|
|
|
|
|
class AddPINEditor extends StatefulWidget {
|
|
|
|
|
final User user;
|
|
|
|
|
AddPINEditor(
|
|
|
|
|
this.user, {
|
|
|
|
|
Key key,
|
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_AddPINEditorState createState() => new _AddPINEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AddPINEditorState extends State<AddPINEditor>
|
|
|
|
|
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 _passwordController = new TextEditingController();
|
|
|
|
|
TextEditingController _pinController = new TextEditingController();
|
|
|
|
|
final formKey = GlobalKey<FormState>();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool isSwitched = 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,
|
|
|
|
|
'change.pin.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,
|
|
|
|
|
// ]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildReset(BuildContext context) {
|
|
|
|
|
final switchBtnBox = Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 20),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'pin.switch',
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
)),
|
|
|
|
|
Switch(
|
|
|
|
|
value: isSwitched,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
isSwitched = value;
|
|
|
|
|
if (!isSwitched) {
|
|
|
|
|
_pinController.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
activeColor: Theme.secondaryColor,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final pinInputBox = Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 25.0, right: 25.0),
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _pinController,
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontFamily: "WorkSansSemiBold",
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
color: Colors.black),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
icon: Image.asset(
|
|
|
|
|
'assets/pin.png',
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
),
|
|
|
|
|
labelText: AppTranslations.of(context).text("change.pin"),
|
|
|
|
|
labelStyle: Provider.of<LanguageModel>(context).isEng
|
|
|
|
|
? TextStyle(fontFamily: "WorkSansSemiBold", color: Colors.grey)
|
|
|
|
|
: TextStyle(fontFamily: "MyanmarUnicode", color: Colors.grey),
|
|
|
|
|
),
|
|
|
|
|
validator: _validatePinCode,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final passwordInputBox = 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("login.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,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final updatePinBtn = Container(
|
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
|
|
|
|
color: Theme.primaryColor,
|
|
|
|
|
),
|
|
|
|
|
child: MaterialButton(
|
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
|
splashColor: Theme.LoginColors.loginGradientEnd,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 42.0),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'pin.add_btn',
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 18.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => _change(context)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final clearPinBtn = 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: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'pin.clear_btn',
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 18.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => _clear(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>[
|
|
|
|
|
switchBtnBox,
|
|
|
|
|
isSwitched ? Container() : pinInputBox,
|
|
|
|
|
Container(
|
|
|
|
|
width: 250.0,
|
|
|
|
|
height: 1.0,
|
|
|
|
|
color: Colors.grey[400],
|
|
|
|
|
),
|
|
|
|
|
passwordInputBox
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
isSwitched ? Container() : updatePinBtn,
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 15,
|
|
|
|
|
),
|
|
|
|
|
!isSwitched ? Container() : clearPinBtn
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _toggleSignup() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_obscureTextSignup = !_obscureTextSignup;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _change(BuildContext context) async {
|
|
|
|
|
if (!formKey.currentState.validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
UserModel userModel = Provider.of<UserModel>(context);
|
|
|
|
|
try {
|
|
|
|
|
await userModel.updatePin(_pinController.text, _passwordController.text);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _clear(BuildContext context) async {
|
|
|
|
|
if (!formKey.currentState.validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
UserModel userModel = Provider.of<UserModel>(context);
|
|
|
|
|
try {
|
|
|
|
|
await userModel.clearPin(_passwordController.text);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} 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 _validatePinCode(value) {
|
|
|
|
|
if (!isSwitched) {
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
return AppTranslations.of(context).text("change.pin_empty");
|
|
|
|
|
}
|
|
|
|
|
if (value.length < 6 || value.length > 6) {
|
|
|
|
|
return AppTranslations.of(context).text("change.pin_size");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|