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