update settins online
This commit is contained in:
parent
4bafd53916
commit
4f974a9338
3 changed files with 36 additions and 9 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class Carts {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Carts {
|
||||
class Settings {
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getSettings(String user) async {
|
||||
|
|
@ -31,21 +31,30 @@ class Carts {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> updateLanguage(String uuid, String language) async {
|
||||
Future<bool> updateLanguage(String user, String language) async {
|
||||
try {
|
||||
await _supabase.from('settings').update({'language': language}).eq('settings_uuid', uuid).select();
|
||||
await _supabase.from('settings').update({'language': language}).eq('user_id', user).select();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateName(String uuid, String name) async {
|
||||
Future<bool> updateName(String user, String name) async {
|
||||
try {
|
||||
await _supabase.from('settings').update({'name': name}).eq('settings_uuid', uuid).select();
|
||||
await _supabase.from('settings').update({'name': name}).eq('user_id', user).select();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkExist(String uuid) async {
|
||||
try {
|
||||
final data = await _supabase.from('settings').select().eq('user_id', uuid);
|
||||
return data.isNotEmpty;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue