diff --git a/lib/view/auth/request_demo_bottom_sheet.dart b/lib/view/auth/request_demo_bottom_sheet.dart index 24c1dd6..4d47856 100644 --- a/lib/view/auth/request_demo_bottom_sheet.dart +++ b/lib/view/auth/request_demo_bottom_sheet.dart @@ -32,6 +32,7 @@ class _OrganizationForm extends StatefulWidget { class _OrganizationFormState extends State<_OrganizationForm> { final MyFormValidator validator = MyFormValidator(); + bool _loading = false; List> _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 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, ); } }