update on settings
This commit is contained in:
parent
5bffc744e3
commit
05c3208cad
9 changed files with 205 additions and 117 deletions
89
lib/pages/customer_pages/customer_settings_page.dart
Normal file
89
lib/pages/customer_pages/customer_settings_page.dart
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_getgueststatus.dart';
|
||||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_title_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/setting_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
|
||||
class CustomerSettingsPage extends StatefulWidget {
|
||||
const CustomerSettingsPage({super.key});
|
||||
|
||||
@override
|
||||
State<CustomerSettingsPage> createState() => _CustomerSettingsPageState();
|
||||
}
|
||||
|
||||
class _CustomerSettingsPageState extends State<CustomerSettingsPage> {
|
||||
final _authService = AuthService();
|
||||
|
||||
late String currentName = '';
|
||||
late bool _isGuest = false;
|
||||
|
||||
void _signOut() async {
|
||||
// ignore: use_build_context_synchronously
|
||||
await _authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
|
||||
}
|
||||
|
||||
Future<bool> _checkGuest() async {
|
||||
final guest = await blocGetGuestStatus(context);
|
||||
return guest;
|
||||
}
|
||||
|
||||
Future<String> _getUsername() async {
|
||||
final username = _authService.getCurrentUser();
|
||||
return username ?? '';
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
final guest = await _checkGuest();
|
||||
if (guest) {
|
||||
_isGuest = guest;
|
||||
} else {
|
||||
currentName = await _getUsername();
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
autoRun();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: CustomerPagebackgroundWidget(
|
||||
child: Column(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
const Gap(68),
|
||||
const CustomerTitleWidget(),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'Settings'),
|
||||
const Gap(16),
|
||||
SettingWidget(
|
||||
icon: Icons.language,
|
||||
title: 'Language',
|
||||
value: 'English',
|
||||
onPressed: () => context.push('/languagesetting')),
|
||||
const Gap(8),
|
||||
SettingWidget(
|
||||
icon: Icons.person,
|
||||
title: 'Display Name',
|
||||
value: _isGuest ? 'Guest' : currentName,
|
||||
),
|
||||
const Gap(32),
|
||||
ButtonWidget(text: 'Log Out', onPressed: _signOut)
|
||||
],
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue