Merge pull request 'fix: Enhance loading state management and error handling in organization form submission' (#39) from Vaibhav_Bug-#427 into main
Reviewed-on: #39
This commit is contained in:
commit
bff814f562
@ -32,6 +32,7 @@ class _OrganizationForm extends StatefulWidget {
|
|||||||
|
|
||||||
class _OrganizationFormState extends State<_OrganizationForm> {
|
class _OrganizationFormState extends State<_OrganizationForm> {
|
||||||
final MyFormValidator validator = MyFormValidator();
|
final MyFormValidator validator = MyFormValidator();
|
||||||
|
bool _loading = false;
|
||||||
|
|
||||||
List<Map<String, dynamic>> _industries = [];
|
List<Map<String, dynamic>> _industries = [];
|
||||||
String? _selectedIndustryId;
|
String? _selectedIndustryId;
|
||||||
@ -148,35 +149,45 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => setState(() => _agreed = !_agreed),
|
onTap: () => setState(() => _agreed = !_agreed),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Checkbox(
|
Checkbox(
|
||||||
value: _agreed,
|
value: _agreed,
|
||||||
onChanged: (val) => setState(() => _agreed = val ?? false),
|
onChanged: (val) =>
|
||||||
fillColor: MaterialStateProperty.resolveWith((states) {
|
setState(() => _agreed = val ?? false),
|
||||||
if (states.contains(MaterialState.selected)) {
|
fillColor: MaterialStateProperty.resolveWith((states) {
|
||||||
return Colors.blueAccent;
|
if (states.contains(MaterialState.selected)) {
|
||||||
}
|
return Colors.blueAccent;
|
||||||
return Colors.white;
|
}
|
||||||
}),
|
return Colors.white;
|
||||||
checkColor: Colors.white,
|
}),
|
||||||
side: const BorderSide(color: Colors.blueAccent, width: 2),
|
checkColor: Colors.white,
|
||||||
),
|
side:
|
||||||
const Expanded(
|
const BorderSide(color: Colors.blueAccent, width: 2),
|
||||||
child: Text('I agree to privacy policy & terms'),
|
),
|
||||||
),
|
const Expanded(
|
||||||
],
|
child: Text('I agree to privacy policy & terms'),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.blueAccent,
|
backgroundColor: Colors.blueAccent,
|
||||||
),
|
),
|
||||||
onPressed: _submitForm,
|
onPressed: _loading ? null : _submitForm,
|
||||||
child: const Text("Submit"),
|
child: _loading
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: Colors.white,
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Text("Submit"),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
@ -297,6 +308,8 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
|
setState(() => _loading = true);
|
||||||
|
|
||||||
final formData = validator.getData();
|
final formData = validator.getData();
|
||||||
|
|
||||||
final Map<String, dynamic> requestBody = {
|
final Map<String, dynamic> requestBody = {
|
||||||
@ -313,6 +326,8 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
|||||||
|
|
||||||
final error = await AuthService.requestDemo(requestBody);
|
final error = await AuthService.requestDemo(requestBody);
|
||||||
|
|
||||||
|
setState(() => _loading = false);
|
||||||
|
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Success",
|
title: "Success",
|
||||||
@ -322,9 +337,9 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
} else {
|
} else {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Success",
|
title: "Error",
|
||||||
message: (error['error'] ?? 'Unknown error'),
|
message: (error['error'] ?? 'Unknown error'),
|
||||||
type: SnackbarType.success,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user