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() {
@ -51,172 +51,229 @@ class _LoginState extends State<Login> {
FocusManager.instance.primaryFocus?.unfocus(); FocusManager.instance.primaryFocus?.unfocus();
}, },
child: SafeArea( child: SafeArea(
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: Column( child: Form(
key: _formKey,
child: Column(
children: <Widget>[ children: <Widget>[
SizedBox(height: MediaQuery.of(context).size.height * .2), SizedBox(height: MediaQuery.of(context).size.height * .2),
CircleAvatar(radius: 80, backgroundColor: Color(0XFFF3F1FB)), CircleAvatar(radius: 80, backgroundColor: Color(0XFFF3F1FB)),
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,),
Container(
Container( child: TextFormField(
child: TextFormField( cursorColor:Color(0XFF8270DB),
cursorColor:Color(0XFF8270DB), obscureText: isObscureText,
obscureText: isObscureText, obscuringCharacter: '*',
obscuringCharacter: '*', controller: passwordController,
controller: passwordController, decoration: InputDecoration(
decoration: InputDecoration( filled: false,
filled: false, fillColor: Colors.white,
fillColor: Colors.white, labelText: 'Password',
labelText: 'Password', //prefixIcon: const Icon(Icons.lock, color: Colors.white,),
//prefixIcon: const Icon(Icons.lock, color: Colors.white,), labelStyle: fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400),
labelStyle: fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400), border: OutlineInputBorder(
border: OutlineInputBorder( borderRadius: BorderRadius.circular(4.0),
borderSide: BorderSide(color: greyColor,
width: 1, )),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0), borderRadius: BorderRadius.circular(4.0),
borderSide: BorderSide(color: greyColor, borderSide: BorderSide(color: Color(0XFF8270DB),width: 2,),
width: 1, )), ),
focusedBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0), borderRadius: BorderRadius.circular(4.0),
borderSide: BorderSide(color: Color(0XFF8270DB),width: 2,), borderSide: BorderSide(color: greyColor),
), ),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0),
borderSide: BorderSide(color: greyColor),
),
suffixIcon: IconButton( suffixIcon: IconButton(
icon: isObscureText==true?Image.asset('images/eye_icon.png',color: Color(0XFF7E7F80),width: 30,height: 30,):Image.asset('images/open_eye.png',color:Color(0XFF7E7F80),width: 30,height: 30,), icon: isObscureText==true?Image.asset('images/eye_icon.png',color: Color(0XFF7E7F80),width: 30,height: 30,):Image.asset('images/open_eye.png',color:Color(0XFF7E7F80),width: 30,height: 30,),
/* Icon( /* Icon(
icon:Image.asset('assets/your_image.png'), icon:Image.asset('assets/your_image.png'),
color: isObscureText==true?greyColor:primaryColor, color: isObscureText==true?greyColor:primaryColor,
),*/ ),*/
onPressed: () { onPressed: () {
print("show password"); print("show password");
setState(() { setState(() {
isObscureText = !isObscureText; isObscureText = !isObscureText;
}); });
}, },
), ),
),
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter password";
}
return null;
},
), ),
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
), ),
),
SizedBox(height:MediaQuery.of(context).size.height * .016,),
SizedBox(height:MediaQuery.of(context).size.height * .016,), Align(
Align( alignment: Alignment.bottomLeft,
alignment: Alignment.bottomLeft, child:GestureDetector(
child:GestureDetector( onTap: (){
onTap: (){ /* Navigator.push(
/* Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => ForgotpasswordNew()), MaterialPageRoute(builder: (context) => ForgotpasswordNew()),
);*/ );*/
}, },
child: Text( child: Text(
'Forgot Password?', 'Forgot Password?',
style: fontTextStyle(12,Color(0XFF1D7AFC),FontWeight.w600), style: fontTextStyle(12,Color(0XFF1D7AFC),FontWeight.w600),
),
)
),
SizedBox(height:MediaQuery.of(context).size.height * .024,),
Container(
width:double.infinity,
height: MediaQuery.of(context).size.height * .06,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0), // Customize the radius
), ),
), )
onPressed: () async{ ),
SizedBox(height:MediaQuery.of(context).size.height * .024,),
Container(
width:double.infinity,
height: MediaQuery.of(context).size.height * .06,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0), // Customize the radius
),
),
onPressed: () async {
// 🔥 THIS MAKES VALIDATION WORK
if (!_formKey.currentState!.validate()) {
return;
}
if (mobileNumberController.text != ''&&
passwordController.text != '') {
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(); var payload = {
payload["password"] = passwordController.text.toString(); "phone": mobileNumberController.text.trim(),
payload["fcmIds"] = [fcmToken]; "password": passwordController.text.trim(),
"fcmIds": [fcmToken]
bool signinStatus = await AppSettings.login(payload); };
try{ bool signinStatus =
if (signinStatus) { await AppSettings.login(payload);
Navigator.of(context,rootNavigator: true).pop();
String token = AppSettings.accessToken; Navigator.of(context,rootNavigator: true).pop();
await storage.write(key: 'authToken', value: token);
if (signinStatus) {
print('Token saved: $token');
await Navigator.push( String token = AppSettings.accessToken;
context,
MaterialPageRoute( await storage.write(
builder: (context) => const DashboardScreen()), key: 'authToken',
); value: token);
AppSettings.longSuccessToast("Logged in Successfully");
mobileNumberController.text=''; Navigator.push(
passwordController.text=''; context,
MaterialPageRoute(
} else { builder: (context) =>
Navigator.of(context,rootNavigator: true).pop(); const DashboardScreen()),
AppSettings.longFailedToast("Invalid details"); );
}
} AppSettings.longSuccessToast(
catch(exception){ "Logged in Successfully");
Navigator.of(context,rootNavigator: true).pop();
print(exception); mobileNumberController.clear();
passwordController.clear();
} else {
AppSettings.longFailedToast(
"Invalid details");
} }
} }
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"); }
}
}, },
child: Text('Login',style: fontTextStyle(12,Colors.white,FontWeight.w600),), child: Text('Login',style: fontTextStyle(12,Colors.white,FontWeight.w600),),
)), )),
], ],
), ),
) )
)), )),
), ),
], ), ],
) )
); );
} }

@ -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;
},
),
], ],
decoration: InputDecoration(
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(
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(
controller: mobileNumberController, key: _formKey,
keyboardType: TextInputType.number, child: Column(
textCapitalization: TextCapitalization.sentences, children: [
maxLength: 10,
decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'), TextFormField(
style:fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400), controller: mobileNumberController,
cursorColor: Color(0XFF8270DB), keyboardType: TextInputType.number,
maxLength: 10,
//TextStyle(color: Colors.black,fontWeight: FontWeight.bold), autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'),
style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400),
cursorColor: Color(0XFF8270DB),
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;
},
),
],
), ),
), ),
@ -75,41 +120,57 @@ class _SignUpMobileNumberScreenState extends State<SignUpMobileNumberScreen> {
BorderRadius.circular(24.0), // Customize the radius BorderRadius.circular(24.0), // Customize the radius
), ),
), ),
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);
if(forgotPwd){ Navigator.of(context,
Navigator.of(context,rootNavigator: true).pop(); rootNavigator: true).pop();
Navigator.push(
context, if(forgotPwd){
new MaterialPageRoute(
builder: (__) => new Otpscreen(mobileNumber:mobileNumberController.text.toString()))); Navigator.push(
context,
MaterialPageRoute(
builder: (__)=>Otpscreen(
mobileNumber:
mobileNumberController.text.trim(),
)));
}
else{
AppSettings.longFailedToast('Please enter valid registered mobile number');
}
} }
else{ else{
Navigator.of(context,rootNavigator: true).pop();
AppSettings.longFailedToast("Please Check internet");
}
AppSettings.longFailedToast(
'Please enter valid registered mobile number');
}
} }
else{ else{
AppSettings.longFailedToast('Please enter 10 digits of mobile number');
Navigator.of(context,
rootNavigator: true).pop();
AppSettings.longFailedToast(
"Please Check internet");
} }
}, },

Loading…
Cancel
Save