mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 19:48:56 +03:30
197 lines
6.9 KiB
Dart
Executable File
197 lines
6.9 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../config/routes.dart';
|
|
import '../../providers/auth.dart';
|
|
import '../../providers/connectivity.dart';
|
|
import '../../widgets/Global/internet_error.dart';
|
|
|
|
class ForgetPassScreen extends StatefulWidget {
|
|
// static const route = '/HomeScreen';
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _ForgetPassScreenState();
|
|
}
|
|
}
|
|
|
|
class _ForgetPassScreenState extends State<ForgetPassScreen> {
|
|
final _form = GlobalKey<FormState>();
|
|
bool _isLoading = false;
|
|
final cellNumberController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
cellNumberController.text = '';
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
void _showDialog(String message) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: Text('Error'),
|
|
content: Text(message),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Ok'),
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _requestCode() async {
|
|
if (!_form.currentState!.validate()) {
|
|
return;
|
|
}
|
|
_form.currentState!.save();
|
|
setState(() {
|
|
_isLoading = true;
|
|
});
|
|
// try {
|
|
await Provider.of<Auth>(context, listen: false)
|
|
.requestCode(
|
|
cellNumberController.text,
|
|
)
|
|
.then(
|
|
(result) {
|
|
if (result == 'NotUser') {
|
|
_showDialog('User Not Found!!!');
|
|
setState(
|
|
() {
|
|
_isLoading = false;
|
|
},
|
|
);
|
|
} else {
|
|
// _showDialog('User or password incorrect!');
|
|
Navigator.of(context).popAndPushNamed(Routes.sendCodeScreen);
|
|
// setState(
|
|
// () {
|
|
// _isLoading = false;
|
|
// },
|
|
// );
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final _media = MediaQuery.of(context);
|
|
// final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5);
|
|
final double _devicewidth = _media.size.width;
|
|
final double _deviceBlockSize = _devicewidth / 100;
|
|
return SafeArea(
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
title: Text('CSSD', style: TextStyle(color: Colors.white,),),
|
|
backgroundColor: Colors.black,
|
|
),
|
|
body: Selector<ConnectivityProvider, String>(
|
|
builder: (ctx, value, _) => value != 'offline'
|
|
? _isLoading
|
|
? Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: Form(
|
|
key: _form,
|
|
child: ListView(
|
|
padding: EdgeInsets.symmetric(horizontal: 20),
|
|
children: <Widget>[
|
|
Container(
|
|
padding: EdgeInsets.symmetric(vertical: 20),
|
|
child: Text(
|
|
'Forget Password',
|
|
textAlign: TextAlign.left,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
letterSpacing: 3,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
TextFormField(
|
|
validator: (value) {
|
|
if (value!.isEmpty) {
|
|
return 'Cell number is required.';
|
|
}
|
|
RegExp regExp =
|
|
RegExp(r'^09[0,1,2,3,9]{1}[0-9]{8}$');
|
|
if (!regExp.hasMatch(value)) {
|
|
return 'Enter a valid cell number';
|
|
}
|
|
return null;
|
|
},
|
|
controller: cellNumberController,
|
|
decoration: InputDecoration(
|
|
icon: Icon(
|
|
Icons.call,
|
|
size: 6 * _deviceBlockSize,
|
|
),
|
|
labelStyle: TextStyle(
|
|
fontWeight: FontWeight.w100,
|
|
fontSize: 4 * _deviceBlockSize,
|
|
),
|
|
labelText: 'Cell Number',
|
|
isDense: true,
|
|
contentPadding: EdgeInsets.symmetric(
|
|
vertical: 2, horizontal: 3),
|
|
),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
keyboardType: TextInputType.phone,
|
|
textInputAction: TextInputAction.next,
|
|
onSaved: (value) {
|
|
cellNumberController.text = value!;
|
|
},
|
|
),
|
|
SizedBox(height: 40),
|
|
Row(
|
|
children: <Widget>[
|
|
InkWell(
|
|
onTap: () => _requestCode(),
|
|
child: Container(
|
|
width: 88 * _deviceBlockSize,
|
|
padding: EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black,
|
|
borderRadius: BorderRadius.circular(7),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'Request Code',
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Spacer(),
|
|
],
|
|
),
|
|
SizedBox(height: 10),
|
|
],
|
|
),
|
|
)
|
|
: ConnectionErrorBox(),
|
|
selector: (_, connectivity) => connectivity.conStatus,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|