Hide country dropdown on subsequent runs once a country is set in local storage
This commit is contained in:
@@ -24,6 +24,7 @@ class OtpHelper extends GetxController {
|
|||||||
'${AppLink.server}/Admin/auth/login.php';
|
'${AppLink.server}/Admin/auth/login.php';
|
||||||
|
|
||||||
var selectedCountry = 'Jordan'.obs;
|
var selectedCountry = 'Jordan'.obs;
|
||||||
|
bool isFirstRun = box.read(BoxName.countryCode) == null;
|
||||||
|
|
||||||
void changeCountry(String country) {
|
void changeCountry(String country) {
|
||||||
selectedCountry.value = country;
|
selectedCountry.value = country;
|
||||||
@@ -288,6 +289,9 @@ class OtpHelper extends GetxController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
|
if (box.read(BoxName.countryCode) == null) {
|
||||||
|
box.write(BoxName.countryCode, 'Jordan');
|
||||||
|
}
|
||||||
selectedCountry.value = box.read(BoxName.countryCode) ?? 'Jordan';
|
selectedCountry.value = box.read(BoxName.countryCode) ?? 'Jordan';
|
||||||
super.onInit();
|
super.onInit();
|
||||||
DeviceHelper.getDeviceFingerprint().then((deviceFingerprint) {
|
DeviceHelper.getDeviceFingerprint().then((deviceFingerprint) {
|
||||||
|
|||||||
@@ -297,58 +297,60 @@ class _AdminLoginPageState extends State<AdminLoginPage>
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
if (Get.find<OtpHelper>().isFirstRun) ...[
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// ── Country Dropdown ───────────────────────────
|
// ── Country Dropdown ───────────────────────────
|
||||||
const Row(
|
const Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.public_rounded,
|
Icon(Icons.public_rounded,
|
||||||
color: _C.accent, size: 16),
|
color: _C.accent, size: 16),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
'الدولة',
|
'الدولة',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: _C.textSec,
|
color: _C.textSec,
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
letterSpacing: 0.3,
|
letterSpacing: 0.3,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
const SizedBox(height: 10),
|
Obx(() {
|
||||||
Obx(() {
|
final otpHelper = Get.find<OtpHelper>();
|
||||||
final otpHelper = Get.find<OtpHelper>();
|
return Container(
|
||||||
return Container(
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
color: _C.inputBg,
|
||||||
color: _C.inputBg,
|
borderRadius: BorderRadius.circular(14),
|
||||||
borderRadius: BorderRadius.circular(14),
|
border: Border.all(color: _C.border, width: 1),
|
||||||
border: Border.all(color: _C.border, width: 1),
|
|
||||||
),
|
|
||||||
child: DropdownButtonHideUnderline(
|
|
||||||
child: DropdownButton<String>(
|
|
||||||
value: otpHelper.selectedCountry.value,
|
|
||||||
icon: const Icon(Icons.arrow_drop_down, color: _C.accent),
|
|
||||||
isExpanded: true,
|
|
||||||
dropdownColor: _C.card,
|
|
||||||
style: const TextStyle(color: _C.textPrimary, fontSize: 16),
|
|
||||||
items: ['Jordan', 'Egypt', 'Syria'].map((String country) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: country,
|
|
||||||
child: Text(country.tr),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (String? val) {
|
|
||||||
if (val != null) {
|
|
||||||
otpHelper.changeCountry(val);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
child: DropdownButtonHideUnderline(
|
||||||
);
|
child: DropdownButton<String>(
|
||||||
}),
|
value: otpHelper.selectedCountry.value,
|
||||||
const SizedBox(height: 28),
|
icon: const Icon(Icons.arrow_drop_down, color: _C.accent),
|
||||||
|
isExpanded: true,
|
||||||
|
dropdownColor: _C.card,
|
||||||
|
style: const TextStyle(color: _C.textPrimary, fontSize: 16),
|
||||||
|
items: ['Jordan', 'Egypt', 'Syria'].map((String country) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: country,
|
||||||
|
child: Text(country.tr),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? val) {
|
||||||
|
if (val != null) {
|
||||||
|
otpHelper.changeCountry(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
const SizedBox(height: 28),
|
||||||
|
],
|
||||||
|
|
||||||
// ── Submit button ────────────────────────────
|
// ── Submit button ────────────────────────────
|
||||||
_isLoading
|
_isLoading
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class LoginController extends GetxController {
|
|||||||
final FlutterSecureStorage storage = const FlutterSecureStorage();
|
final FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
|
|
||||||
var selectedCountry = 'Jordan'.obs;
|
var selectedCountry = 'Jordan'.obs;
|
||||||
|
bool isFirstRun = box.read(BoxName.countryCode) == null;
|
||||||
|
|
||||||
void changeCountry(String country) {
|
void changeCountry(String country) {
|
||||||
selectedCountry.value = country;
|
selectedCountry.value = country;
|
||||||
@@ -184,6 +185,9 @@ class LoginController extends GetxController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() async {
|
void onInit() async {
|
||||||
|
if (box.read(BoxName.countryCode) == null) {
|
||||||
|
await box.write(BoxName.countryCode, 'Jordan');
|
||||||
|
}
|
||||||
selectedCountry.value = box.read(BoxName.countryCode) ?? 'Jordan';
|
selectedCountry.value = box.read(BoxName.countryCode) ?? 'Jordan';
|
||||||
await EncryptionHelper.initialize();
|
await EncryptionHelper.initialize();
|
||||||
await DeviceHelper.getDeviceFingerprint();
|
await DeviceHelper.getDeviceFingerprint();
|
||||||
|
|||||||
@@ -100,37 +100,37 @@ class LoginPage extends StatelessWidget {
|
|||||||
hint: 'أدخل كلمة المرور',
|
hint: 'أدخل كلمة المرور',
|
||||||
type: TextInputType.visiblePassword,
|
type: TextInputType.visiblePassword,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
if (controller.isFirstRun) ...[
|
||||||
|
Obx(() => Container(
|
||||||
Obx(() => Container(
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
color: Colors.grey.withOpacity(0.08),
|
||||||
color: Colors.grey.withOpacity(0.08),
|
borderRadius: BorderRadius.circular(16),
|
||||||
borderRadius: BorderRadius.circular(16),
|
border: Border.all(color: Colors.grey.withOpacity(0.2)),
|
||||||
border: Border.all(color: Colors.grey.withOpacity(0.2)),
|
|
||||||
),
|
|
||||||
child: DropdownButtonHideUnderline(
|
|
||||||
child: DropdownButton<String>(
|
|
||||||
value: controller.selectedCountry.value,
|
|
||||||
icon: const Icon(Icons.arrow_drop_down, color: AppColor.blueColor),
|
|
||||||
isExpanded: true,
|
|
||||||
dropdownColor: Colors.white,
|
|
||||||
style: const TextStyle(color: Colors.black87, fontSize: 16),
|
|
||||||
items: ['Jordan', 'Egypt', 'Syria'].map((String country) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: country,
|
|
||||||
child: Text(country.tr),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (String? val) {
|
|
||||||
if (val != null) {
|
|
||||||
controller.changeCountry(val);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
child: DropdownButtonHideUnderline(
|
||||||
)),
|
child: DropdownButton<String>(
|
||||||
const SizedBox(height: 40),
|
value: controller.selectedCountry.value,
|
||||||
|
icon: const Icon(Icons.arrow_drop_down, color: AppColor.blueColor),
|
||||||
|
isExpanded: true,
|
||||||
|
dropdownColor: Colors.white,
|
||||||
|
style: const TextStyle(color: Colors.black87, fontSize: 16),
|
||||||
|
items: ['Jordan', 'Egypt', 'Syria'].map((String country) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: country,
|
||||||
|
child: Text(country.tr),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? val) {
|
||||||
|
if (val != null) {
|
||||||
|
controller.changeCountry(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
const SizedBox(height: 40),
|
||||||
|
],
|
||||||
|
|
||||||
// Login Button
|
// Login Button
|
||||||
Container(
|
Container(
|
||||||
|
|||||||
Reference in New Issue
Block a user