login and signup

master
gitadmin 2 months ago
parent 0bdaa99c55
commit d087c10ca5

@ -26,7 +26,7 @@ class _LoginState extends State<Login> {
bool isObscureText=true; bool isObscureText=true;
TextEditingController mobileNumberController = TextEditingController(); TextEditingController mobileNumberController = TextEditingController();
TextEditingController passwordController = TextEditingController(); TextEditingController passwordController = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override @override
void initState() { void initState() {
@ -54,6 +54,8 @@ class _LoginState extends State<Login> {
child: SingleChildScrollView( child: SingleChildScrollView(
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 0), padding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
child: Form(
key: _formKey,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
@ -62,18 +64,56 @@ class _LoginState extends State<Login> {
SizedBox(height: MediaQuery.of(context).size.height * .05), SizedBox(height: MediaQuery.of(context).size.height * .05),
SizedBox(height:MediaQuery.of(context).size.height * .024,), SizedBox(height:MediaQuery.of(context).size.height * .024,),
Container( TextFormField(
child: TextFormField(
controller: mobileNumberController, controller: mobileNumberController,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
textCapitalization: TextCapitalization.sentences,
maxLength: 10, maxLength: 10,
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'), decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'),
style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400), style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400),
cursorColor: Color(0XFF8270DB), cursorColor: Color(0XFF8270DB),
//TextStyle(color: Colors.black,fontWeight: FontWeight.bold), inputFormatters: [
// Allow only numbers
FilteringTextInputFormatter.digitsOnly,
// Restrict first digit 6-9
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
), ),
],
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter mobile number";
}
if (!RegExp(r'^[6-9]').hasMatch(value)) {
return "Please enter digits 6,7,8,9";
}
if (value.length != 10) {
return "Enter valid 10 digit number";
}
return null;
},
), ),
SizedBox(height:MediaQuery.of(context).size.height * .016,), SizedBox(height:MediaQuery.of(context).size.height * .016,),
@ -119,7 +159,12 @@ class _LoginState extends State<Login> {
), ),
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400), style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter password";
}
return null;
},
), ),
), ),
@ -154,58 +199,70 @@ class _LoginState extends State<Login> {
), ),
onPressed: () async { onPressed: () async {
if (mobileNumberController.text != ''&& // 🔥 THIS MAKES VALIDATION WORK
passwordController.text != '') { if (!_formKey.currentState!.validate()) {
return;
}
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
bool isOnline = await AppSettings.internetConnectivity(); bool isOnline = await AppSettings.internetConnectivity();
if(isOnline){ if(isOnline){
SharedPreferences prefs = await SharedPreferences.getInstance();
SharedPreferences prefs =
await SharedPreferences.getInstance();
String? fcmToken = prefs.getString('fcmToken'); String? fcmToken = prefs.getString('fcmToken');
var payload = new Map<String, dynamic>();
payload["phone"] = mobileNumberController.text.toString();
payload["password"] = passwordController.text.toString();
payload["fcmIds"] = [fcmToken];
bool signinStatus = await AppSettings.login(payload); var payload = {
"phone": mobileNumberController.text.trim(),
"password": passwordController.text.trim(),
"fcmIds": [fcmToken]
};
bool signinStatus =
await AppSettings.login(payload);
try{
if (signinStatus) {
Navigator.of(context,rootNavigator: true).pop(); Navigator.of(context,rootNavigator: true).pop();
if (signinStatus) {
String token = AppSettings.accessToken; String token = AppSettings.accessToken;
await storage.write(key: 'authToken', value: token);
print('Token saved: $token'); await storage.write(
await Navigator.push( key: 'authToken',
value: token);
Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const DashboardScreen()), builder: (context) =>
const DashboardScreen()),
); );
AppSettings.longSuccessToast("Logged in Successfully");
mobileNumberController.text=''; AppSettings.longSuccessToast(
passwordController.text=''; "Logged in Successfully");
mobileNumberController.clear();
passwordController.clear();
} else { } else {
Navigator.of(context,rootNavigator: true).pop();
AppSettings.longFailedToast("Invalid details"); AppSettings.longFailedToast(
} "Invalid details");
}
catch(exception){
Navigator.of(context,rootNavigator: true).pop();
print(exception);
} }
} }
else{ else{
Navigator.of(context,rootNavigator: true).pop();
AppSettings.longFailedToast("Please Check internet");
}
Navigator.of(context,
rootNavigator: true).pop();
} AppSettings.longFailedToast(
else{ "Please Check internet");
AppSettings.longFailedToast("Please enter valid details");
} }
}, },
@ -216,7 +273,7 @@ class _LoginState extends State<Login> {
) )
)), )),
), ),
], ), ],
) )
); );
} }

@ -26,6 +26,9 @@ class _FleetEmployeesState extends State<FleetEmployees> {
final _mobileCtrl = TextEditingController(); final _mobileCtrl = TextEditingController();
final _altMobileCtrl = TextEditingController(); final _altMobileCtrl = TextEditingController();
final _locationCtrl = TextEditingController(); final _locationCtrl = TextEditingController();
final _experienceController = TextEditingController();
final _licenseController = TextEditingController();
final List<String> licenseNumbers = [ final List<String> licenseNumbers = [
"UP3220050012345", "UP3220050012345",
@ -91,10 +94,7 @@ class _FleetEmployeesState extends State<FleetEmployees> {
Future<void> _addDriver() async { Future<void> _addDriver() async {
if (!(_formKey.currentState?.validate() ?? false)) return; if (!(_formKey.currentState?.validate() ?? false)) return;
if (selectedLicense == null || selectedExperience == null) {
AppSettings.longFailedToast("Select License & Experience");
return;
}
var payload = { var payload = {
"Name": _nameCtrl.text.trim(), "Name": _nameCtrl.text.trim(),
@ -373,6 +373,7 @@ class _FleetEmployeesState extends State<FleetEmployees> {
controller: _nameCtrl, controller: _nameCtrl,
validator: (v) => _required(v, field: "Driver Name"), validator: (v) => _required(v, field: "Driver Name"),
textCapitalization: TextCapitalization.none, textCapitalization: TextCapitalization.none,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: const [ inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps FirstCharUppercaseFormatter(), // << live first-letter caps
], ],
@ -386,81 +387,105 @@ class _FleetEmployeesState extends State<FleetEmployees> {
), ),
_LabeledField( _LabeledField(
label: "Driver License Number *", label: "Driver License Number *",
child: DropdownButtonFormField<String>( child: TextFormField(
value: selectedLicense, controller: _licenseController, // create controller
dropdownColor: Colors.white,
items: licenseNumbers
.map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(),
onChanged: (v) => setState(() => selectedLicense = v),
validator: (v) => v == null || v.isEmpty
? "Driver License required"
: null,
isExpanded: true,
alignment: Alignment.centerLeft,
hint: Text(
"Select License Number",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png',
width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, hintText: "Enter License Number",
contentPadding: EdgeInsets.symmetric(
horizontal: 12, vertical: 14), contentPadding:
EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
autovalidateMode: AutovalidateMode.onUserInteraction,
style: fontTextStyle(
14, const Color(0xFF2A2A2A), FontWeight.w400),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return "Driver License required";
}
return null;
},
), ),
), ),
_LabeledField( _LabeledField(
label: "Years of Experience *", label: "Years of Experience *",
child: DropdownButtonFormField<String>( child: TextFormField(
value: selectedExperience, controller: _experienceController, // create controller
dropdownColor: Colors.white, keyboardType: TextInputType.number,
items: yearOptions autovalidateMode: AutovalidateMode.onUserInteraction,
.map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(),
onChanged: (v) =>
setState(() => selectedExperience = v),
validator: (v) => v == null || v.isEmpty
? "Experience is required"
: null,
isExpanded: true,
alignment: Alignment.centerLeft,
hint: Text(
"Years",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png',
width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, hintText: "Enter Years",
contentPadding: EdgeInsets.symmetric( contentPadding:
horizontal: 12, vertical: 14), EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
style: fontTextStyle(
14, const Color(0xFF2A2A2A), FontWeight.w400),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return "Experience is required";
}
return null;
},
), ),
), ),
_LabeledField( _LabeledField(
label: "Phone Number *", label: "Phone Number *",
child: TextFormField( child: TextFormField(
controller: _mobileCtrl, controller: _mobileCtrl,
validator: (v) => _validatePhone(v),
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
// Restrict first digit 6-9
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
),
], ],
validator: (value) {
if (value == null || value.isEmpty) {
return "Phone Number required";
}
if (!RegExp(r'^[6-9]').hasMatch(value)) {
return "Enter digits starting 6,7,8,9";
}
if (value.length != 10) {
return "Enter valid 10 digit number";
}
return null;
},
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), hintStyle: fontTextStyle(
border: OutlineInputBorder(), 14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next,
), ),
), ),
_LabeledField( _LabeledField(
@ -468,9 +493,27 @@ class _FleetEmployeesState extends State<FleetEmployees> {
child: TextFormField( child: TextFormField(
controller: _altMobileCtrl, controller: _altMobileCtrl,
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
// Restrict first digit 6-9
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
),
], ],
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
@ -486,6 +529,7 @@ class _FleetEmployeesState extends State<FleetEmployees> {
controller: _locationCtrl, controller: _locationCtrl,
validator: (v) => _required(v, field: "Location"), validator: (v) => _required(v, field: "Location"),
textCapitalization: TextCapitalization.none, textCapitalization: TextCapitalization.none,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: const [ inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps FirstCharUppercaseFormatter(), // << live first-letter caps
], ],
@ -511,6 +555,7 @@ class _FleetEmployeesState extends State<FleetEmployees> {
validator: (v) => v == null || v.isEmpty ? "Status is required" : null, validator: (v) => v == null || v.isEmpty ? "Status is required" : null,
isExpanded: true, isExpanded: true,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
autovalidateMode: AutovalidateMode.onUserInteraction,
hint: Text( hint: Text(
"Select status", "Select status",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
@ -525,12 +570,36 @@ class _FleetEmployeesState extends State<FleetEmployees> {
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
ElevatedButton( ElevatedButton(
onPressed: _addDriver, onPressed: () {
if (_formKey.currentState!.validate()) {
_addDriver();
// Reset form validation
_formKey.currentState!.reset();
// Clear TextFields
_mobileCtrl.clear();
_licenseController.clear(); // Driver License
_experienceController.clear();
_locationCtrl.clear(); // Location field
_nameCtrl.clear();
// Reset variables (if any)
selectedLicense = null;
selectedExperience = null;
setState(() {});
}
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF8270DB), backgroundColor: const Color(0xFF8270DB),
foregroundColor: Colors.white, foregroundColor: Colors.white,
minimumSize: const Size(343, 41), // Width & Height minimumSize: const Size(343, 41),
padding: const EdgeInsets.fromLTRB(24, 12, 24, 12),), padding: const EdgeInsets.fromLTRB(24, 12, 24, 12),
),
child: const Text("Add Driver"), child: const Text("Add Driver"),
), ),
], ],

@ -172,6 +172,7 @@ class _SourceLocationState extends State<SourceLocation> {
controller: _nameCtrl, controller: _nameCtrl,
validator: (v) => _required(v, field: "Location Name"), validator: (v) => _required(v, field: "Location Name"),
textCapitalization: TextCapitalization.none, textCapitalization: TextCapitalization.none,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: const [ inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps FirstCharUppercaseFormatter(), // << live first-letter caps
], ],
@ -186,21 +187,58 @@ class _SourceLocationState extends State<SourceLocation> {
), ),
_LabeledField( _LabeledField(
label: "Mobile Number *", label: "Phone Number *",
child: TextFormField( child: TextFormField(
controller: _mobileCtrl, controller: _mobileCtrl,
validator: (v) => _validatePhone(v, label: "Mobile Number"),
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
// Restrict first digit 6-9
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
),
], ],
validator: (value) {
if (value == null || value.isEmpty) {
return "Phone Number required";
}
if (!RegExp(r'^[6-9]').hasMatch(value)) {
return "Enter digits starting 6,7,8,9";
}
if (value.length != 10) {
return "Enter valid 10 digit number";
}
return null;
},
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), hintStyle: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
), ),
), ),
@ -324,7 +362,9 @@ class _SourceLocationState extends State<SourceLocation> {
hint: Text( hint: Text(
"Select Water Type", "Select Water Type",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
), ),
autovalidateMode: AutovalidateMode.onUserInteraction,
icon: Image.asset('images/downarrow.png', width: 16, height: 16), icon: Image.asset('images/downarrow.png', width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),

@ -56,6 +56,8 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
final _mobileCtrl = TextEditingController(); final _mobileCtrl = TextEditingController();
final _altMobileCtrl = TextEditingController(); final _altMobileCtrl = TextEditingController();
final _locationCtrl = TextEditingController(); final _locationCtrl = TextEditingController();
final _licenseController = TextEditingController();
final _experienceController = TextEditingController();
// Unused in UI but kept if you later need them // Unused in UI but kept if you later need them
final _commissionCtrl = TextEditingController(); final _commissionCtrl = TextEditingController();
@ -256,6 +258,7 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
controller: _nameCtrl, controller: _nameCtrl,
validator: (v) => _required(v, field: "Driver Name"), validator: (v) => _required(v, field: "Driver Name"),
textCapitalization: TextCapitalization.none, textCapitalization: TextCapitalization.none,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: const [ inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps FirstCharUppercaseFormatter(), // << live first-letter caps
], ],
@ -272,64 +275,49 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
_LabeledField( _LabeledField(
label: "Driver License Number *", label: "Driver License Number *",
child: DropdownButtonFormField<String>( child: TextFormField(
value: selectedLicense, controller: _licenseController, // create controller
dropdownColor: Colors.white,
items: licenseNumbers
.map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(),
onChanged: (v) => setState(() => selectedLicense = v),
validator: (v) => v == null || v.isEmpty
? "Driver License required"
: null,
isExpanded: true,
alignment: Alignment.centerLeft,
hint: Text(
"Select License Number",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png',
width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, hintText: "Enter License Number",
contentPadding: EdgeInsets.symmetric( contentPadding:
horizontal: 12, vertical: 14), EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
style: fontTextStyle(
14, const Color(0xFF2A2A2A), FontWeight.w400),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return "Driver License required";
}
return null;
},
), ),
), ),
_LabeledField( _LabeledField(
label: "Years of Experience *", label: "Years of Experience *",
child: DropdownButtonFormField<String>( child: TextFormField(
value: selectedExperience, controller: _experienceController, // create controller
dropdownColor: Colors.white, keyboardType: TextInputType.number,
items: yearOptions autovalidateMode: AutovalidateMode.onUserInteraction,
.map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(),
onChanged: (v) =>
setState(() => selectedExperience = v),
validator: (v) => v == null || v.isEmpty
? "Experience is required"
: null,
isExpanded: true,
alignment: Alignment.centerLeft,
hint: Text(
"Years",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png',
width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, hintText: "Enter Years",
contentPadding: EdgeInsets.symmetric( contentPadding:
horizontal: 12, vertical: 14), EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
style: fontTextStyle(
14, const Color(0xFF2A2A2A), FontWeight.w400),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return "Experience is required";
}
return null;
},
), ),
), ),
@ -337,13 +325,47 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
label: "Phone Number *", label: "Phone Number *",
child: TextFormField( child: TextFormField(
controller: _mobileCtrl, controller: _mobileCtrl,
validator: (v) =>
_validatePhone(v, label: "Phone Number"),
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
// Restrict first digit 6-9
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
),
], ],
validator: (value) {
if (value == null || value.isEmpty) {
return "Phone Number required";
}
if (!RegExp(r'^[6-9]').hasMatch(value)) {
return "Enter digits starting 6,7,8,9";
}
if (value.length != 10) {
return "Enter valid 10 digit number";
}
return null;
},
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
hintStyle: fontTextStyle( hintStyle: fontTextStyle(
@ -351,6 +373,7 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
), ),
), ),
@ -366,6 +389,7 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
label: "Alternate Phone Number"); label: "Alternate Phone Number");
}, },
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
@ -387,6 +411,7 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
controller: _locationCtrl, controller: _locationCtrl,
validator: (v) => _required(v, field: "Location"), validator: (v) => _required(v, field: "Location"),
textCapitalization: TextCapitalization.none, textCapitalization: TextCapitalization.none,
autovalidateMode: AutovalidateMode.onUserInteraction,
inputFormatters: const [ inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps FirstCharUppercaseFormatter(), // << live first-letter caps
], ],
@ -418,9 +443,12 @@ class _ResourcesDriverScreenState extends State<ResourcesDriverScreen> {
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
hint: Text( hint: Text(
"Select status", "Select status",
style: fontTextStyle( style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400), 14, const Color(0xFF939495), FontWeight.w400),
), ),
autovalidateMode: AutovalidateMode.onUserInteraction,
icon: const Icon(Icons.keyboard_arrow_down_rounded), icon: const Icon(Icons.keyboard_arrow_down_rounded),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),

@ -14,7 +14,7 @@ class SignUpMobileNumberScreen extends StatefulWidget {
class _SignUpMobileNumberScreenState extends State<SignUpMobileNumberScreen> { class _SignUpMobileNumberScreenState extends State<SignUpMobileNumberScreen> {
TextEditingController mobileNumberController = TextEditingController(); TextEditingController mobileNumberController = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -48,17 +48,62 @@ class _SignUpMobileNumberScreenState extends State<SignUpMobileNumberScreen> {
), ),
), ),
SizedBox(height:MediaQuery.of(context).size.height * .016,), SizedBox(height:MediaQuery.of(context).size.height * .016,),
Container(
child: TextFormField( Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: mobileNumberController, controller: mobileNumberController,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
textCapitalization: TextCapitalization.sentences,
maxLength: 10, maxLength: 10,
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'), decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'),
style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400), style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400),
cursorColor: Color(0XFF8270DB), cursorColor: Color(0XFF8270DB),
//TextStyle(color: Colors.black,fontWeight: FontWeight.bold), inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
TextInputFormatter.withFunction(
(oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
// First digit must be 6-9
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
return oldValue;
}
return newValue;
},
),
],
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter mobile number";
}
if (!RegExp(r'^[6-9]').hasMatch(value)) {
return "Please enter digits 6,7,8,9";
}
if (value.length != 10) {
return "Enter valid 10 digit number";
}
return null;
},
),
],
), ),
), ),
@ -76,41 +121,57 @@ class _SignUpMobileNumberScreenState extends State<SignUpMobileNumberScreen> {
), ),
), ),
onPressed: () async { onPressed: () async {
if(mobileNumberController.text.length>=10){
if (!_formKey.currentState!.validate()) {
return;
}
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
bool isOnline = await AppSettings.internetConnectivity(); bool isOnline =
await AppSettings.internetConnectivity();
if(isOnline){ if(isOnline){
var payload = new Map<String, dynamic>(); var payload = {
payload["phone"] = mobileNumberController.text.toString(); "phone":
mobileNumberController.text.trim()
};
bool forgotPwd =
await AppSettings.getOtp(payload);
bool forgotPwd = await AppSettings.getOtp(payload); Navigator.of(context,
rootNavigator: true).pop();
if(forgotPwd){ if(forgotPwd){
Navigator.of(context,rootNavigator: true).pop();
Navigator.push( Navigator.push(
context, context,
new MaterialPageRoute( MaterialPageRoute(
builder: (__) => new Otpscreen(mobileNumber:mobileNumberController.text.toString()))); builder: (__)=>Otpscreen(
mobileNumber:
mobileNumberController.text.trim(),
)));
} }
else{ else{
AppSettings.longFailedToast('Please enter valid registered mobile number');
AppSettings.longFailedToast(
'Please enter valid registered mobile number');
} }
} }
else{ else{
Navigator.of(context,rootNavigator: true).pop();
AppSettings.longFailedToast("Please Check internet");
}
Navigator.of(context,
rootNavigator: true).pop();
AppSettings.longFailedToast(
"Please Check internet");
} }
else{
AppSettings.longFailedToast('Please enter 10 digits of mobile number');
}
}, },
child: Text( child: Text(

Loading…
Cancel
Save