This commit is contained in:
Patrick Alvin Alcala 2025-03-06 12:17:14 +08:00
parent 7749f1100d
commit 1b0241037d
7 changed files with 74 additions and 56 deletions

View file

@ -4,11 +4,13 @@ import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:pharmacy_mobile/auth/auth_service.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
class MainPage extends StatefulWidget {
const MainPage({super.key});
@ -20,9 +22,28 @@ class MainPage extends StatefulWidget {
class _MainPageState extends State<MainPage> {
final _authService = AuthService();
late bool _isLoading = false;
void signOut() async {
// ignore: use_build_context_synchronously
await _authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
try {
setState(() {
_isLoading = true;
});
// ignore: use_build_context_synchronously
await _authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
} catch (e) {
if (e is AuthException) {
final errorMessage = e.message;
if (mounted) {
showNotification(context, 'Error: $errorMessage', false);
}
}
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
@ -109,10 +130,8 @@ class _MainPageState extends State<MainPage> {
onPressed: () => {context.push('/liststocks')},
color: 'yellow'),
const Gap(40),
ButtonWidget(
text: 'Logout',
onPressed: signOut,
)
ButtonWithProgressWidget(
trigger: _isLoading, progressText: 'Logging Out', buttonText: 'Logout', onPressed: signOut)
],
),
),