update settins online

This commit is contained in:
Patrick Alvin Alcala 2025-03-27 11:23:47 +08:00
parent 4bafd53916
commit 4f974a9338
3 changed files with 36 additions and 9 deletions

View file

@ -4,6 +4,7 @@ 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/functions/getlanguage_function.dart';
import 'package:pharmacy_mobile/tables/settings.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';
@ -21,6 +22,7 @@ class CustomerSettingsPage extends StatefulWidget {
class _CustomerSettingsPageState extends State<CustomerSettingsPage> {
static const List<String> languageList = ['English', 'Tagalog', 'Hilogaynon (Ilonggo)', 'Cebuano (Bisaya)'];
final _authService = AuthService();
final _settings = Settings();
late String currentName = '';
late bool _isGuest = false;
@ -47,8 +49,26 @@ class _CustomerSettingsPageState extends State<CustomerSettingsPage> {
currentLanguage = await getLanguage(context);
setState(() {});
//delay this for 1 second
await Future.delayed(Duration(seconds: 1));
final user = _authService.getCurrentUserId()!;
final language = currentLanguage;
final name = '';
final exist = await _settings.checkExist(user);
if (exist) {
final updateSetting = await _settings.updateLanguage(user, currentLanguage);
if (!updateSetting) {
// ignore: use_build_context_synchronously
showNotification(context, 'Settings not updated online', false);
}
} else {
final settingsSaved = await _settings.postSettings(user, language, name);
if (!settingsSaved) {
// ignore: use_build_context_synchronously
showNotification(context, 'Settings not saved online', false);
}
}
}
void autoRun() async {