add pin login and add pin code
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/model/language_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pin_input_text_field/pin_input_text_field.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../helpers/shared_pref.dart';
|
||||
import '../../localization/app_translations.dart';
|
||||
|
||||
class PinLoginPage extends StatefulWidget {
|
||||
//final User user;
|
||||
const PinLoginPage({super.key});
|
||||
|
||||
@override
|
||||
@@ -18,10 +23,77 @@ class _PinLoginPageState extends State<PinLoginPage> {
|
||||
bool _isLoading = false;
|
||||
String pin = "";
|
||||
String prefixText = "FCS-";
|
||||
//late User _user;
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
TextEditingController _fcsIdCtl = new TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() async {
|
||||
await SharedPref.setPinLockOn(true);
|
||||
}
|
||||
|
||||
Future<bool> _onWillPop() async {
|
||||
// Show the confirmation dialog
|
||||
return (await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Center(
|
||||
child:
|
||||
LocalText(context, 'btn.exit_confirm', color: primaryColor),
|
||||
),
|
||||
content: Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: Colors.grey[300],
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5.0))),
|
||||
child: Text(
|
||||
AppTranslations.of(context)!.text('btn.cancel'),
|
||||
style: Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(color: primaryColor)
|
||||
: TextStyle(
|
||||
fontFamily: 'Myanmar3', color: primaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
}),
|
||||
SizedBox(
|
||||
width: 0,
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: primaryColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5.0))),
|
||||
child: Text(AppTranslations.of(context)!.text('btn.ok'),
|
||||
style: Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold)
|
||||
: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'Myanmar3')),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)) ??
|
||||
false;
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
final fcsIdBox = TextFormField(
|
||||
controller: _fcsIdCtl,
|
||||
@@ -48,7 +120,7 @@ class _PinLoginPageState extends State<PinLoginPage> {
|
||||
prefixText,
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
|
||||
prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
|
||||
contentPadding: EdgeInsets.all(0),
|
||||
labelStyle: newLabelStyle(color: Colors.black54, fontSize: 17),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
@@ -121,42 +193,47 @@ class _PinLoginPageState extends State<PinLoginPage> {
|
||||
callBack: _login,
|
||||
),
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: new Scaffold(
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: EdgeInsets.only(top: 80, left: 15, right: 15, bottom: 20),
|
||||
children: [
|
||||
pinLoginLogo,
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20, bottom: 20),
|
||||
child: Center(
|
||||
child: LocalText(context, "welcome.pinlogin",
|
||||
color: Colors.black, fontSize: 18),
|
||||
|
||||
// ignore: deprecated_member_use
|
||||
return WillPopScope(
|
||||
onWillPop: _onWillPop,
|
||||
child: LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: new Scaffold(
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: EdgeInsets.only(top: 80, left: 15, right: 15, bottom: 20),
|
||||
children: [
|
||||
pinLoginLogo,
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20, bottom: 20),
|
||||
child: Center(
|
||||
child: LocalText(context, "welcome.pinlogin",
|
||||
color: Colors.black, fontSize: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
LocalText(
|
||||
context,
|
||||
"welcome.pinlogin.fcsid",
|
||||
color: Colors.black54,
|
||||
fontSize: 15,
|
||||
),
|
||||
fcsIdBox,
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 25, bottom: 20),
|
||||
child: LocalText(
|
||||
context,
|
||||
"welcome.pinlogin.pin",
|
||||
color: Colors.black54,
|
||||
fontSize: 15,
|
||||
)),
|
||||
pinInputBox,
|
||||
loginBtn,
|
||||
],
|
||||
),
|
||||
)),
|
||||
LocalText(
|
||||
context,
|
||||
"welcome.pinlogin.fcsid",
|
||||
color: Colors.black54,
|
||||
fontSize: 15,
|
||||
),
|
||||
fcsIdBox,
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 25, bottom: 20),
|
||||
child: LocalText(
|
||||
context,
|
||||
"welcome.pinlogin.pin",
|
||||
color: Colors.black54,
|
||||
fontSize: 15,
|
||||
)),
|
||||
pinInputBox,
|
||||
loginBtn,
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -171,14 +248,14 @@ class _PinLoginPageState extends State<PinLoginPage> {
|
||||
return;
|
||||
}
|
||||
String fcsId = "$prefixText${_fcsIdCtl.text}";
|
||||
print(fcsId);
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
Navigator.pop(context, true);
|
||||
await context.read<MainModel>().pinLogin(fcsID: fcsId, pin: pin);
|
||||
Navigator.pushNamedAndRemoveUntil(context, "/home", (r) => false);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user