FIX: adiciona changeNotifica no toggleNotify

This commit is contained in:
J. A. Messias 2024-11-01 15:05:54 -03:00
parent 3dadb48fe8
commit fe772eaf2a
1 changed files with 23 additions and 20 deletions

View File

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:hub/backend/api_requests/api_calls.dart';
import 'package:hub/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart';
@ -45,23 +47,32 @@ class PreferencesPageModel with ChangeNotifier {
);
onConfirm() async {
String content;
try {
content = FFLocalizations.of(context).getVariableText(
enText: 'Notification changed successfully',
ptText: 'Notificação alterada com sucesso',
);
context.pop();
SnackBarUtil.showSnackBar(context, content);
StorageUtil().notify = !StorageUtil().notify;
notifyListeners();
} catch (err) {
String value = StorageUtil().notify ? 'N' : 'S';
await PhpGroup.changeNotifica.call(notifica: value).then((value) async {
if (value.jsonBody['error'] == false) {
StorageUtil().notify = !StorageUtil().notify;
notifyListeners();
content = FFLocalizations.of(context).getVariableText(
enText: 'Notification changed successfully',
ptText: 'Notificação alterada com sucesso',
);
SnackBarUtil.showSnackBar(context, content);
} else {
content = FFLocalizations.of(context).getVariableText(
enText: 'Error changing notification',
ptText: 'Erro ao alterar notificação',
);
SnackBarUtil.showSnackBar(context, content, isError: true);
}
}).catchError((e, s) {
log('toggleNotify', error: e, stackTrace: s);
content = FFLocalizations.of(context).getVariableText(
enText: 'Error changing notification',
ptText: 'Erro ao alterar notificação',
);
context.pop();
SnackBarUtil.showSnackBar(context, content, isError: true);
}
}).whenComplete(() => notifyListeners());
context.pop();
}
showAlertDialog(context, title, content, onConfirm);
@ -200,13 +211,6 @@ class PreferencesPageModel with ChangeNotifier {
showAlertDialog(context, title, content, onConfirm);
}
void _showPassKey(BuildContext context, void Function(String) onChange) async {
await showModalBottomSheet(
isScrollControlled: true,
@ -231,5 +235,4 @@ class PreferencesPageModel with ChangeNotifier {
SnackBarUtil.showSnackBar(context, content, isError: true);
}).whenComplete(() => notifyListeners());
}
}