2024-02-14 16:54:38 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2024-02-15 16:38:57 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2024-02-14 16:54:38 +06:30
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
class PinLoginPage extends StatefulWidget {
|
2024-02-19 17:06:58 +06:30
|
|
|
//final User user;
|
2024-02-14 16:54:38 +06:30
|
|
|
const PinLoginPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<PinLoginPage> createState() => _PinLoginPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PinLoginPageState extends State<PinLoginPage> {
|
|
|
|
|
bool _isLoading = false;
|
2024-02-19 17:06:58 +06:30
|
|
|
String pin = "";
|
|
|
|
|
//late User _user;
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
2024-02-14 17:19:55 +06:30
|
|
|
TextEditingController _fcsIdCtl = new TextEditingController();
|
|
|
|
|
|
2024-02-14 16:54:38 +06:30
|
|
|
@override
|
|
|
|
|
void initState() {
|
2024-02-15 16:38:57 +06:30
|
|
|
//_user=widget.user;
|
|
|
|
|
//pin = _user.pinDigit ?? "";
|
2024-02-14 16:54:38 +06:30
|
|
|
super.initState();
|
2024-02-15 16:38:57 +06:30
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
2024-02-14 16:54:38 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-14 17:19:55 +06:30
|
|
|
final fcsIdBox = TextFormField(
|
|
|
|
|
controller: _fcsIdCtl,
|
|
|
|
|
autofocus: true,
|
2024-02-19 17:06:58 +06:30
|
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
|
return 'Please enter FCS ID';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
2024-02-14 17:19:55 +06:30
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 15, color: Colors.black87, fontWeight: FontWeight.w500),
|
|
|
|
|
cursorColor: primaryColor,
|
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
|
|
|
|
labelStyle: newLabelStyle(color: Colors.black54, fontSize: 17),
|
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
disabledBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
2024-02-19 17:06:58 +06:30
|
|
|
errorStyle: TextStyle(color: dangerColor),
|
2024-02-14 17:19:55 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final pinLoginLogo = Container(
|
|
|
|
|
width: 70,
|
|
|
|
|
height: 70,
|
|
|
|
|
child: FittedBox(
|
|
|
|
|
child: Image.asset(
|
|
|
|
|
"assets/logo.jpg",
|
|
|
|
|
),
|
|
|
|
|
fit: BoxFit.fitHeight,
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-02-19 17:06:58 +06:30
|
|
|
final pinInputBox = FormField(
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (pin == "") {
|
|
|
|
|
return "Please enter PIN";
|
|
|
|
|
}
|
|
|
|
|
if (pin.length < 6) {
|
|
|
|
|
return "PIN must be 6 digit";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
|
|
|
builder: (state) {
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
PinInputTextField(
|
|
|
|
|
cursor: Cursor(
|
|
|
|
|
color: primaryColor, enabled: true, width: 2, height: 23),
|
|
|
|
|
pinLength: 6,
|
|
|
|
|
decoration: BoxLooseDecoration(
|
|
|
|
|
strokeColorBuilder: PinListenColorBuilder(
|
|
|
|
|
primaryColor, Colors.grey.shade400),
|
|
|
|
|
errorTextStyle: TextStyle(color: dangerColor)),
|
|
|
|
|
textInputAction: TextInputAction.done,
|
|
|
|
|
autoFocus: false,
|
|
|
|
|
onChanged: _pinChange,
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
|
child: pin == "" || pin.length < 6
|
|
|
|
|
? SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
child: Text(state.errorText ?? "",
|
|
|
|
|
style: TextStyle(color: dangerColor, fontSize: 12)),
|
|
|
|
|
)
|
|
|
|
|
: const SizedBox(height: 20),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
});
|
2024-02-14 17:19:55 +06:30
|
|
|
|
|
|
|
|
final loginBtn = Padding(
|
|
|
|
|
padding: EdgeInsets.only(top: 30),
|
|
|
|
|
child: LocalButton(
|
|
|
|
|
textKey: "welcome.pinlogin",
|
2024-02-15 16:38:57 +06:30
|
|
|
callBack: _login,
|
2024-02-14 17:19:55 +06:30
|
|
|
),
|
|
|
|
|
);
|
2024-02-14 16:54:38 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: new Scaffold(
|
2024-02-15 16:38:57 +06:30
|
|
|
// appBar: LocalAppBar(
|
|
|
|
|
// backgroundColor: primaryColor,
|
2024-02-19 17:06:58 +06:30
|
|
|
|
2024-02-15 16:38:57 +06:30
|
|
|
// ),
|
2024-02-19 17:06:58 +06:30
|
|
|
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),
|
2024-02-14 17:19:55 +06:30
|
|
|
),
|
2024-02-19 17:06:58 +06:30
|
|
|
),
|
|
|
|
|
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,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)),
|
2024-02-14 17:19:55 +06:30
|
|
|
);
|
2024-02-14 16:54:38 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_pinChange(pin) {
|
|
|
|
|
setState(() {
|
|
|
|
|
this.pin = pin;
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-02-19 17:06:58 +06:30
|
|
|
|
2024-02-15 16:38:57 +06:30
|
|
|
_login() async {
|
2024-02-19 17:06:58 +06:30
|
|
|
if (pin == "" && _formKey.currentState!.validate()) {
|
2024-02-15 16:38:57 +06:30
|
|
|
showMsgDialog(context, "Error", "Invalid PIN");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 17:06:58 +06:30
|
|
|
if (pin.length < 6 && _formKey.currentState!.validate()) {
|
2024-02-15 16:38:57 +06:30
|
|
|
showMsgDialog(context, "Error", "PIN must be 6 digits");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-19 17:06:58 +06:30
|
|
|
if (!_formKey.currentState!.validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 16:38:57 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-14 16:54:38 +06:30
|
|
|
}
|