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:
vaibhav.surve 2025-06-03 09:49:31 +00:00
commit bff814f562

View File

@ -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;
@ -153,7 +154,8 @@ class _OrganizationFormState extends State<_OrganizationForm> {
children: [ children: [
Checkbox( Checkbox(
value: _agreed, value: _agreed,
onChanged: (val) => setState(() => _agreed = val ?? false), onChanged: (val) =>
setState(() => _agreed = val ?? false),
fillColor: MaterialStateProperty.resolveWith((states) { fillColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) { if (states.contains(MaterialState.selected)) {
return Colors.blueAccent; return Colors.blueAccent;
@ -161,7 +163,8 @@ class _OrganizationFormState extends State<_OrganizationForm> {
return Colors.white; return Colors.white;
}), }),
checkColor: Colors.white, checkColor: Colors.white,
side: const BorderSide(color: Colors.blueAccent, width: 2), side:
const BorderSide(color: Colors.blueAccent, width: 2),
), ),
const Expanded( const Expanded(
child: Text('I agree to privacy policy & terms'), child: Text('I agree to privacy policy & terms'),
@ -169,14 +172,22 @@ class _OrganizationFormState extends State<_OrganizationForm> {
], ],
), ),
), ),
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,
); );
} }
} }