Skip to content

Commit

Permalink
fixed TextField of Map API isEmpty validation (#226)
Browse files Browse the repository at this point in the history
* fixed TextField of Map API isEmpty validation

* stateful widget removed

* business logic seperated

* Update pubspec.lock

* Update settings_controller.dart

* Delete pubspec.lock

---------

Co-authored-by: Prince Patel <[email protected]>
Co-authored-by: Rijuth Menon <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent 11c41a0 commit 3556d98
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1,402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SettingsController extends GetxController {
final Rx<WeatherKeyState> weatherKeyState = WeatherKeyState.add.obs;
final RxBool didWeatherKeyError = false.obs;
final RxBool showingCircularProgressIndicator = false.obs;
RxBool validate = false.obs;

UserModel? userModel;
@override
Expand Down
27 changes: 27 additions & 0 deletions lib/app/modules/settings/views/weather_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class WeatherApi extends StatelessWidget {
TextField(
obscureText: false,
controller: controller.apiKey,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'API Key',
errorText: controller.validate.value
? 'API Key cannot be empty'
: null,
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
Expand Down Expand Up @@ -88,6 +95,26 @@ class WeatherApi extends StatelessWidget {
.showingCircularProgressIndicator
.value = true;

// Validation If String is empty
if (await controller
.apiKey.text.isEmpty) {
// setState(() {
controller.validate.value = true;
// });
controller
.showingCircularProgressIndicator
.value = false;
return;
}

// Reset state after getting error message
if (await controller
.apiKey.text.isNotEmpty) {
// setState(() {
controller.validate.value = false;
// });
}

// Get the user's location
await controller.getLocation();

Expand Down
Loading

0 comments on commit 3556d98

Please sign in to comment.