bug fixing
parent
39571be9c6
commit
9b956574ae
@ -1,140 +1,175 @@
|
|||||||
import 'dart:async';
|
// import 'dart:async';
|
||||||
|
//
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
// import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:car_provider_app/generated/locale_keys.g.dart';
|
// import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/material.dart';
|
// import 'package:mc_common_app/extensions/int_extensions.dart';
|
||||||
import 'package:mc_common_app/extensions/int_extensions.dart';
|
// import 'package:mc_common_app/extensions/string_extensions.dart';
|
||||||
import 'package:mc_common_app/extensions/string_extensions.dart';
|
// import 'package:mc_common_app/generated/locale_keys.g.dart';
|
||||||
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
// import 'package:mc_common_app/models/user_models/country.dart';
|
||||||
import 'package:mc_common_app/models/user_models/country.dart';
|
// import 'package:mc_common_app/theme/colors.dart';
|
||||||
import 'package:mc_common_app/theme/colors.dart';
|
// import 'package:mc_common_app/utils/navigator.dart';
|
||||||
import 'package:mc_common_app/utils/navigator.dart';
|
// import 'package:mc_common_app/utils/utils.dart';
|
||||||
import 'package:mc_common_app/utils/utils.dart';
|
// import 'package:mc_common_app/view_models/user_view_model.dart';
|
||||||
import 'package:mc_common_app/view_models/user_view_model.dart';
|
// import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
||||||
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
// import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
||||||
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
// import 'package:mc_common_app/widgets/txt_field.dart';
|
||||||
import 'package:mc_common_app/widgets/txt_field.dart';
|
// import 'package:provider/provider.dart';
|
||||||
import 'package:provider/provider.dart';
|
//
|
||||||
|
// class AddPhoneNumWidget extends StatefulWidget {
|
||||||
class AddPhoneNumWidget extends StatefulWidget {
|
// const AddPhoneNumWidget({Key? key}) : super(key: key);
|
||||||
const AddPhoneNumWidget({Key? key}) : super(key: key);
|
//
|
||||||
|
// @override
|
||||||
@override
|
// State<AddPhoneNumWidget> createState() => _AddPhoneNumWidgetState();
|
||||||
State<AddPhoneNumWidget> createState() => _AddPhoneNumWidgetState();
|
// }
|
||||||
}
|
//
|
||||||
|
// class _AddPhoneNumWidgetState extends State<AddPhoneNumWidget> {
|
||||||
class _AddPhoneNumWidgetState extends State<AddPhoneNumWidget> {
|
// String phoneNum = "", countryCode = "";
|
||||||
String phoneNum = "", countryCode = "";
|
// late UserVM userVM;
|
||||||
late UserVM userVM;
|
// Country? _country;
|
||||||
Country? _country;
|
//
|
||||||
|
// @override
|
||||||
@override
|
// void initState() {
|
||||||
void initState() {
|
// super.initState();
|
||||||
super.initState();
|
//
|
||||||
|
// scheduleMicrotask(() {
|
||||||
scheduleMicrotask(() {
|
// userVM = Provider.of(context, listen: false);
|
||||||
userVM = Provider.of(context, listen: false);
|
// getCountryList();
|
||||||
getCountryList();
|
// });
|
||||||
});
|
// }
|
||||||
}
|
//
|
||||||
|
// getCountryList() async {
|
||||||
getCountryList() async {
|
// _country = await userVM.getAllCountries();
|
||||||
_country = await userVM.getAllCountries();
|
// setState(() {});
|
||||||
setState(() {});
|
// }
|
||||||
}
|
//
|
||||||
|
// @override
|
||||||
@override
|
// Widget build(BuildContext context) {
|
||||||
Widget build(BuildContext context) {
|
// return Padding(
|
||||||
return Padding(
|
// padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||||
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
// child: Container(
|
||||||
child: Container(
|
// width: double.infinity,
|
||||||
width: double.infinity,
|
// padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
||||||
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
// child: Column(
|
||||||
child: Column(
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
// mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
// mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
// children: [
|
||||||
children: [
|
// "Enter Phone Number".toText(fontSize: 16, isBold: true),
|
||||||
"Enter Phone Number".toText(fontSize: 16, isBold: true),
|
// 8.height,
|
||||||
8.height,
|
// getCountry(context),
|
||||||
getCountry(context),
|
// 8.height,
|
||||||
8.height,
|
// TxtField(
|
||||||
TxtField(
|
// keyboardType: TextInputType.phone,
|
||||||
keyboardType: TextInputType.phone,
|
// hint: "Phone without country code",
|
||||||
hint: "546758594",
|
// value: phoneNum,
|
||||||
value: phoneNum,
|
// isSidePaddingZero: true,
|
||||||
isSidePaddingZero: true,
|
// onChanged: (v) {
|
||||||
onChanged: (v) {
|
// // Remove any spaces, dashes, or parentheses
|
||||||
phoneNum = v;
|
// String cleanedValue = v.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
||||||
},
|
//
|
||||||
),
|
// // Remove leading + if present
|
||||||
16.height,
|
// if (cleanedValue.startsWith('+')) {
|
||||||
Row(
|
// cleanedValue = cleanedValue.substring(1);
|
||||||
children: [
|
// }
|
||||||
Expanded(
|
//
|
||||||
child: ShowFillButton(
|
// // If country code is selected, remove it from the input if user entered it
|
||||||
title: "Cancel",
|
// if (countryCode.isNotEmpty) {
|
||||||
backgroundColor: MyColors.greyButtonColor,
|
// String codeWithoutPlus = countryCode.replaceAll('+', '');
|
||||||
txtColor: Colors.black,
|
//
|
||||||
onPressed: () {
|
// // Check if the cleaned value starts with the country code
|
||||||
pop(context);
|
// if (cleanedValue.startsWith(codeWithoutPlus)) {
|
||||||
},
|
// cleanedValue = cleanedValue.substring(codeWithoutPlus.length);
|
||||||
),
|
// }
|
||||||
),
|
//
|
||||||
12.width,
|
// // Also check for common variations (e.g., 00966 instead of +966)
|
||||||
Expanded(
|
// if (cleanedValue.startsWith('00$codeWithoutPlus')) {
|
||||||
child: ShowFillButton(
|
// cleanedValue = cleanedValue.substring(codeWithoutPlus.length + 2);
|
||||||
title: LocaleKeys.sendOTP.tr(),
|
// } else if (cleanedValue.startsWith('00')) {
|
||||||
onPressed: () {
|
// // Remove 00 prefix if present
|
||||||
//User Role: Dealer|Manager for a branch
|
// cleanedValue = cleanedValue.substring(2);
|
||||||
FocusScope.of(context).unfocus();
|
// // Check again if it starts with country code after removing 00
|
||||||
if (validation()) {
|
// if (cleanedValue.startsWith(codeWithoutPlus)) {
|
||||||
userVM.performBasicOtpRegisterPage(context, countryCode: countryCode, phoneNum: phoneNum, role: 7, isNeedToPassToken: true, reloadPage: () {
|
// cleanedValue = cleanedValue.substring(codeWithoutPlus.length);
|
||||||
pop(context);
|
// }
|
||||||
});
|
// }
|
||||||
}
|
// }
|
||||||
},
|
//
|
||||||
),
|
// // Remove leading zeros (but keep at least one digit if that's all there is)
|
||||||
),
|
// while (cleanedValue.length > 1 && cleanedValue.startsWith('0')) {
|
||||||
],
|
// cleanedValue = cleanedValue.substring(1);
|
||||||
)
|
// }
|
||||||
],
|
//
|
||||||
),
|
// phoneNum = cleanedValue;
|
||||||
),
|
// setState(() {}); // Update UI to show cleaned value
|
||||||
);
|
// },
|
||||||
}
|
// ),
|
||||||
|
// 16.height,
|
||||||
Widget getCountry(BuildContext context) {
|
// Row(
|
||||||
if (_country != null) {
|
// children: [
|
||||||
List<DropValue> dropList = [];
|
// Expanded(
|
||||||
_country!.data?.forEach((element) {
|
// child: ShowFillButton(
|
||||||
dropList.add(DropValue(element.id ?? 0, "${element.countryName ?? ""} ${element.countryCode ?? ""}", element.countryCode ?? ""));
|
// title: "Cancel",
|
||||||
});
|
// backgroundColor: MyColors.greyButtonColor,
|
||||||
return DropdownField(
|
// txtColor: Colors.black,
|
||||||
(DropValue value) {
|
// onPressed: () {
|
||||||
countryCode = value.subValue;
|
// pop(context);
|
||||||
},
|
// },
|
||||||
list: dropList,
|
// ),
|
||||||
hint: countryCode.isNotEmpty ? countryCode.toString() : LocaleKeys.selectCountryCode.tr(),
|
// ),
|
||||||
);
|
// 12.width,
|
||||||
} else {
|
// Expanded(
|
||||||
return const Center(
|
// child: ShowFillButton(
|
||||||
child: CircularProgressIndicator(),
|
// title: LocaleKeys.sendOTP.tr(),
|
||||||
);
|
// onPressed: () {
|
||||||
}
|
// //User Role: Dealer|Manager for a branch
|
||||||
}
|
// FocusScope.of(context).unfocus();
|
||||||
|
// if (validation()) {
|
||||||
bool validation() {
|
// userVM.performBasicOtpRegisterPage(context, countryCode: countryCode, phoneNum: phoneNum, role: 7, isNeedToPassToken: true, reloadPage: () {
|
||||||
bool isValid = true;
|
// pop(context);
|
||||||
if (countryCode.isEmpty) {
|
// });
|
||||||
Utils.showToast(LocaleKeys.selectCountryCode.tr());
|
// }
|
||||||
//("Please select Country Code");
|
// },
|
||||||
isValid = false;
|
// ),
|
||||||
} else if (phoneNum.isEmpty) {
|
// ),
|
||||||
Utils.showToast(LocaleKeys.addPhoneNo.tr());
|
// ],
|
||||||
//("Please add Phone No");
|
// )
|
||||||
isValid = false;
|
// ],
|
||||||
}
|
// ),
|
||||||
return isValid;
|
// ),
|
||||||
}
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// Widget getCountry(BuildContext context) {
|
||||||
|
// if (_country != null) {
|
||||||
|
// List<DropValue> dropList = [];
|
||||||
|
// _country!.data?.forEach((element) {
|
||||||
|
// dropList.add(DropValue(element.id ?? 0, "${element.countryName ?? ""} ${element.countryCode ?? ""}", element.countryCode ?? ""));
|
||||||
|
// });
|
||||||
|
// return DropdownField(
|
||||||
|
// (DropValue value) {
|
||||||
|
// countryCode = value.subValue;
|
||||||
|
// },
|
||||||
|
// list: dropList,
|
||||||
|
// hint: countryCode.isNotEmpty ? countryCode.toString() : LocaleKeys.selectCountryCode.tr(),
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// return const Center(
|
||||||
|
// child: CircularProgressIndicator(),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// bool validation() {
|
||||||
|
// bool isValid = true;
|
||||||
|
// if (countryCode.isEmpty) {
|
||||||
|
// Utils.showToast(LocaleKeys.selectCountryCode.tr());
|
||||||
|
// //("Please select Country Code");
|
||||||
|
// isValid = false;
|
||||||
|
// } else if (phoneNum.isEmpty) {
|
||||||
|
// Utils.showToast(LocaleKeys.addPhoneNo.tr());
|
||||||
|
// //("Please add Phone No");
|
||||||
|
// isValid = false;
|
||||||
|
// }
|
||||||
|
// return isValid;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
Loading…
Reference in New Issue