Hide country dropdown on subsequent runs once a country is set in local storage

This commit is contained in:
Hamza-Ayed
2026-06-29 00:45:47 +03:00
parent c4fd859257
commit b5e2bf2fed
4 changed files with 89 additions and 79 deletions

View File

@@ -22,6 +22,7 @@ class LoginController extends GetxController {
final FlutterSecureStorage storage = const FlutterSecureStorage();
var selectedCountry = 'Jordan'.obs;
bool isFirstRun = box.read(BoxName.countryCode) == null;
void changeCountry(String country) {
selectedCountry.value = country;
@@ -184,6 +185,9 @@ class LoginController extends GetxController {
@override
void onInit() async {
if (box.read(BoxName.countryCode) == null) {
await box.write(BoxName.countryCode, 'Jordan');
}
selectedCountry.value = box.read(BoxName.countryCode) ?? 'Jordan';
await EncryptionHelper.initialize();
await DeviceHelper.getDeviceFingerprint();

View File

@@ -100,37 +100,37 @@ class LoginPage extends StatelessWidget {
hint: 'أدخل كلمة المرور',
type: TextInputType.visiblePassword,
),
const SizedBox(height: 20),
Obx(() => Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.08),
borderRadius: BorderRadius.circular(16),
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);
}
},
if (controller.isFirstRun) ...[
Obx(() => Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.08),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.grey.withOpacity(0.2)),
),
),
)),
const SizedBox(height: 40),
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);
}
},
),
),
)),
const SizedBox(height: 40),
],
// Login Button
Container(