fix pets and ios foreground notification

This commit is contained in:
J. A. Messias 2024-09-13 10:52:46 -03:00
parent 8878ea6e09
commit 3da294a09e
6 changed files with 112 additions and 48 deletions

View File

@ -74,6 +74,7 @@ class AppState extends ChangeNotifier {
await _safeInitAsync(() async {
_cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID;
});
await _safeInitAsync(() async {
_ownerUUID = await secureStorage.getString('ff_ownerUUID') ?? _ownerUUID;
});
@ -166,6 +167,10 @@ class AppState extends ChangeNotifier {
await _safeInitAsync(() async {
_haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal;
});
await _safeInitAsync(() async {
_petAmountRegister =
await secureStorage.getInt('petAmountRegister') ?? _petAmountRegister;
});
await _safeInitAsync(() async {
_isRequestOSNotification =
@ -180,6 +185,18 @@ class AppState extends ChangeNotifier {
}
late FlutterSecureStorage secureStorage;
int _petAmountRegister = 0;
int get petAmountRegister => _petAmountRegister;
set petAmountRegister(int value) {
_petAmountRegister = value;
secureStorage.setInt('petAmountRegister', value);
}
void deletePetAmountRegister() {
secureStorage.delete(key: 'petAmountRegister');
}
bool _isRequestOSNotification = false;
bool get isRequestOSNotification => _isRequestOSNotification;
set isRequestOSNotification(bool value) {

View File

@ -1,4 +1,5 @@
import 'dart:developer';
import 'dart:io';
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:firebase_core/firebase_core.dart';
@ -48,10 +49,12 @@ Future<void> initializeApp() async {
}
Future<void> foregroundHandleMessage(RemoteMessage message) async {
NotificationService.show(
title: message.notification!.title!,
body: message.notification!.body!,
payload: Map<String, String>.from(message.data));
if (!Platform.isIOS) {
NotificationService.show(
title: message.notification!.title!,
body: message.notification!.body!,
payload: Map<String, String>.from(message.data));
}
}
Future<void> _backgroundHandleMessage(RemoteMessage message) async {}

View File

@ -51,6 +51,8 @@ class _HomePageWidgetState extends State<HomePageWidget> {
AppState().whatsapp = response.jsonBody['whatsapp'] ?? false;
AppState().provisional = response.jsonBody['provisional'] ?? false;
AppState().pets = response.jsonBody['pet'] ?? false;
AppState().petAmountRegister =
response.jsonBody['petAmountRegister'] ?? '0';
AppState().name = response.jsonBody['visitado']['VDO_NOME'];
safeSetState(() {});
return;

View File

@ -141,10 +141,21 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
controller: _scrollController,
itemCount: _petsWrap.length,
itemCount: _petsWrap.length + 1,
itemBuilder: (context, index) {
final item = _petsWrap[index];
return _item(context, item);
if (index == 0) {
// Add your item here
return Padding(
padding: EdgeInsets.only(right: 30, top: 10),
child: Text(
"${_petsWrap.length}/${AppState().petAmountRegister}",
textAlign: TextAlign.right,
),
);
} else {
final item = _petsWrap[index - 1];
return _item(context, item);
}
});
},
)),

View File

@ -11,10 +11,12 @@ import '/custom_code/actions/index.dart' as actions;
class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
late final TabController tabBarController;
VoidCallback? onUpdatePet;
ApiCallResponse? petsResponse;
int? petId;
BuildContext? buildContext;
bool isEditing = false;
// Controller para o Upload de Arquivos
bool isDataUploading = false;
@ -204,6 +206,8 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
enText: 'Pet successfully updated',
ptText: 'Pet atualizado com sucesso',
));
clearFields();
switchTab(1);
}).catchError((error) {
log(error.toString());
DialogUtil.errorDefault(buildContext!);
@ -239,8 +243,36 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
enText: 'Pet successfully registered',
ptText: 'Pet cadastrado com sucesso',
));
clearFields();
}).catchError((error) {
DialogUtil.errorDefault(buildContext!);
});
}
void switchTab(int index) {
tabBarController.animateTo(index);
if (index == 1) handleEditingChanged(false);
onUpdatePet?.call();
}
void handleUploadComplete(FFUploadedFile uploadedFile) {
uploadedLocalFile = uploadedFile;
}
void handleEditingChanged(bool editing) {
isEditing = editing;
clearFields();
}
void clearFields() {
uploadedLocalFile = null;
textControllerName.text = '';
textControllerSpecies.text = '';
textControllerRace.text = '';
textControllerColor.text = '';
textControllerData.text = '';
textControllerObservation.text = '';
dropDownValueController1 = FormFieldController<String>('');
dropDownValueController2 = FormFieldController<String>('');
}
}

View File

@ -52,15 +52,17 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
with SingleTickerProviderStateMixin {
late PetsPageModel _model;
final _formKey = GlobalKey<FormState>();
bool isEditing = false;
@override
void initState() {
super.initState();
_model = PetsPageModel();
_model.tabBarController = TabController(length: 2, vsync: this);
_model.onUpdatePet = () {
setState(() {});
};
widget.pet != null ? isEditing = true : isEditing = false;
widget.pet != null ? _model.isEditing = true : _model.isEditing = false;
// _handleUploadComplete(actions.convertToUploadFile())
@ -73,40 +75,47 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
'https://freaccess.com.br/freaccess/getImage.php?devUUID=${AppState().devUUID}&userUUID=${AppState().userUUID}&cliID=${AppState().cliUUID}&atividade=consultaFotoPet&petId=$petId'));
String base64 = base64Encode(response.bodyBytes);
FFUploadedFile uploadedFile = await convertToUploadFile(base64);
_handleUploadComplete(uploadedFile);
setState(() {
_model.handleUploadComplete(uploadedFile);
});
})();
}
_model.textControllerName ??= TextEditingController(
text: widget.pet != null ? widget.pet['name'] : '');
text: widget.pet != null ? widget.pet['name'] ?? '' : '');
_model.textFieldFocusName ??= FocusNode();
_model.textControllerSpecies ??= TextEditingController(
text: widget.pet != null ? widget.pet['species'] : '');
text: widget.pet != null ? widget.pet['species'] ?? '' : '');
_model.textFieldFocusSpecies ??= FocusNode();
_model.textControllerRace ??= TextEditingController(
text: widget.pet != null ? widget.pet['breed'] : '');
text: widget.pet != null ? widget.pet['breed'] ?? '' : '');
_model.textFieldFocusRace ??= FocusNode();
_model.textControllerColor ??= TextEditingController(
text: widget.pet != null ? widget.pet['color'] : '');
text: widget.pet != null ? widget.pet['color'] ?? '' : '');
_model.textFieldFocusColor ??= FocusNode();
_model.textControllerData ??= TextEditingController(
text: widget.pet != null
? ValidatorUtil.formatDateTimePicker(widget.pet['birthdayDate'])
? widget.pet['birthdayDate'] != null
? ValidatorUtil.formatDateTimePicker(widget.pet['birthdayDate'])
: ''
: '');
_model.textFieldFocusData ??= FocusNode();
_model.textControllerObservation ??= TextEditingController(
text: widget.pet != null ? widget.pet['notes'] : '');
text: widget.pet != null ? widget.pet['notes'] ?? '' : '');
_model.textFieldFocusObservation ??= FocusNode();
if (widget.pet != null) {
_model.dropDownValue1 ??= widget.pet['gender'] ?? '';
_model.dropDownValue2 ??= widget.pet['size'] ?? '';
}
widget.pet != null
? _model.dropDownValue1 ??= widget.pet['gender'] ?? ''
: _model.dropDownValue1 ??= '';
widget.pet != null
? _model.dropDownValue2 ??= widget.pet['size'] ?? ''
: _model.dropDownValue2 ??= '';
_model.dropDownValueController1 ??=
FormFieldController<String>(_model.dropDownValue1 ??= '');
@ -121,30 +130,10 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
_model.dispose();
}
void _handleUploadComplete(FFUploadedFile uploadedFile) {
setState(() {
_model.uploadedLocalFile = uploadedFile;
});
}
void _handleEditingChanged(bool editing) {
setState(() {
isEditing = editing;
_model.uploadedLocalFile = null;
_model.textControllerName.text = '';
_model.textControllerSpecies.text = '';
_model.textControllerRace.text = '';
_model.textControllerColor.text = '';
_model.textControllerData.text = '';
_model.textControllerObservation.text = '';
_model.dropDownValueController1 = FormFieldController<String>('');
_model.dropDownValueController2 = FormFieldController<String>('');
});
}
@override
Widget build(BuildContext context) {
_model.buildContext = context;
return Scaffold(
appBar: _buildAppBar(context),
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
@ -152,14 +141,23 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
}
PreferredSizeWidget _buildAppBar(BuildContext context) {
return AppBarUtil(title: 'Pets', onBackButtonPressed: () => context.pop());
return AppBarUtil(
title: 'Pets',
onBackButtonPressed: () => context.pop(),
);
}
void onEditingChanged(bool value) {
setState(() {
_model.handleEditingChanged(value);
});
}
Widget _buildTabView(BuildContext context) {
return TabViewUtil(
context: context,
model: _model,
labelTab1: isEditing
labelTab1: _model.isEditing
? FFLocalizations.of(context)
.getVariableText(ptText: 'Editar', enText: 'Edit')
: FFLocalizations.of(context)
@ -167,10 +165,11 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
labelTab2: FFLocalizations.of(context)
.getVariableText(ptText: 'Consultar', enText: 'History'),
controller: _model.tabBarController,
widget1:
isEditing ? _buildEditForm(context) : _buildRegisterForm(context),
widget1: _model.isEditing
? _buildEditForm(context)
: _buildRegisterForm(context),
widget2: PetsHistoryScreen(),
onEditingChanged: _handleEditingChanged,
onEditingChanged: onEditingChanged,
);
}
@ -208,7 +207,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 20),
child: MediaUploadButtonUtil(
onUploadComplete: _handleUploadComplete,
onUploadComplete: _model.handleUploadComplete,
isUploading: _model.isDataUploading,
uploadedFiles: _model.uploadedLocalFile,
labelText: FFLocalizations.of(context).getVariableText(
@ -666,7 +665,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 20),
child: MediaUploadButtonUtil(
onUploadComplete: _handleUploadComplete,
onUploadComplete: _model.handleUploadComplete,
isUploading: _model.isDataUploading,
uploadedFiles: _model.uploadedLocalFile,
labelText: FFLocalizations.of(context).getVariableText(