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 { await _safeInitAsync(() async {
_cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID; _cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID;
}); });
await _safeInitAsync(() async { await _safeInitAsync(() async {
_ownerUUID = await secureStorage.getString('ff_ownerUUID') ?? _ownerUUID; _ownerUUID = await secureStorage.getString('ff_ownerUUID') ?? _ownerUUID;
}); });
@ -166,6 +167,10 @@ class AppState extends ChangeNotifier {
await _safeInitAsync(() async { await _safeInitAsync(() async {
_haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal; _haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal;
}); });
await _safeInitAsync(() async {
_petAmountRegister =
await secureStorage.getInt('petAmountRegister') ?? _petAmountRegister;
});
await _safeInitAsync(() async { await _safeInitAsync(() async {
_isRequestOSNotification = _isRequestOSNotification =
@ -180,6 +185,18 @@ class AppState extends ChangeNotifier {
} }
late FlutterSecureStorage secureStorage; 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 _isRequestOSNotification = false;
bool get isRequestOSNotification => _isRequestOSNotification; bool get isRequestOSNotification => _isRequestOSNotification;
set isRequestOSNotification(bool value) { set isRequestOSNotification(bool value) {

View File

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

View File

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

View File

@ -141,10 +141,21 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
shrinkWrap: true, shrinkWrap: true,
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
controller: _scrollController, controller: _scrollController,
itemCount: _petsWrap.length, itemCount: _petsWrap.length + 1,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final item = _petsWrap[index]; if (index == 0) {
return _item(context, item); // 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> { class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
late final TabController tabBarController; late final TabController tabBarController;
VoidCallback? onUpdatePet;
ApiCallResponse? petsResponse; ApiCallResponse? petsResponse;
int? petId; int? petId;
BuildContext? buildContext; BuildContext? buildContext;
bool isEditing = false;
// Controller para o Upload de Arquivos // Controller para o Upload de Arquivos
bool isDataUploading = false; bool isDataUploading = false;
@ -204,6 +206,8 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
enText: 'Pet successfully updated', enText: 'Pet successfully updated',
ptText: 'Pet atualizado com sucesso', ptText: 'Pet atualizado com sucesso',
)); ));
clearFields();
switchTab(1);
}).catchError((error) { }).catchError((error) {
log(error.toString()); log(error.toString());
DialogUtil.errorDefault(buildContext!); DialogUtil.errorDefault(buildContext!);
@ -239,8 +243,36 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
enText: 'Pet successfully registered', enText: 'Pet successfully registered',
ptText: 'Pet cadastrado com sucesso', ptText: 'Pet cadastrado com sucesso',
)); ));
clearFields();
}).catchError((error) { }).catchError((error) {
DialogUtil.errorDefault(buildContext!); 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 { with SingleTickerProviderStateMixin {
late PetsPageModel _model; late PetsPageModel _model;
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
bool isEditing = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_model = PetsPageModel(); _model = PetsPageModel();
_model.tabBarController = TabController(length: 2, vsync: this); _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()) // _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')); '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); String base64 = base64Encode(response.bodyBytes);
FFUploadedFile uploadedFile = await convertToUploadFile(base64); FFUploadedFile uploadedFile = await convertToUploadFile(base64);
_handleUploadComplete(uploadedFile); setState(() {
_model.handleUploadComplete(uploadedFile);
});
})(); })();
} }
_model.textControllerName ??= TextEditingController( _model.textControllerName ??= TextEditingController(
text: widget.pet != null ? widget.pet['name'] : ''); text: widget.pet != null ? widget.pet['name'] ?? '' : '');
_model.textFieldFocusName ??= FocusNode(); _model.textFieldFocusName ??= FocusNode();
_model.textControllerSpecies ??= TextEditingController( _model.textControllerSpecies ??= TextEditingController(
text: widget.pet != null ? widget.pet['species'] : ''); text: widget.pet != null ? widget.pet['species'] ?? '' : '');
_model.textFieldFocusSpecies ??= FocusNode(); _model.textFieldFocusSpecies ??= FocusNode();
_model.textControllerRace ??= TextEditingController( _model.textControllerRace ??= TextEditingController(
text: widget.pet != null ? widget.pet['breed'] : ''); text: widget.pet != null ? widget.pet['breed'] ?? '' : '');
_model.textFieldFocusRace ??= FocusNode(); _model.textFieldFocusRace ??= FocusNode();
_model.textControllerColor ??= TextEditingController( _model.textControllerColor ??= TextEditingController(
text: widget.pet != null ? widget.pet['color'] : ''); text: widget.pet != null ? widget.pet['color'] ?? '' : '');
_model.textFieldFocusColor ??= FocusNode(); _model.textFieldFocusColor ??= FocusNode();
_model.textControllerData ??= TextEditingController( _model.textControllerData ??= TextEditingController(
text: widget.pet != null text: widget.pet != null
? ValidatorUtil.formatDateTimePicker(widget.pet['birthdayDate']) ? widget.pet['birthdayDate'] != null
? ValidatorUtil.formatDateTimePicker(widget.pet['birthdayDate'])
: ''
: ''); : '');
_model.textFieldFocusData ??= FocusNode(); _model.textFieldFocusData ??= FocusNode();
_model.textControllerObservation ??= TextEditingController( _model.textControllerObservation ??= TextEditingController(
text: widget.pet != null ? widget.pet['notes'] : ''); text: widget.pet != null ? widget.pet['notes'] ?? '' : '');
_model.textFieldFocusObservation ??= FocusNode(); _model.textFieldFocusObservation ??= FocusNode();
if (widget.pet != null) { widget.pet != null
_model.dropDownValue1 ??= widget.pet['gender'] ?? ''; ? _model.dropDownValue1 ??= widget.pet['gender'] ?? ''
_model.dropDownValue2 ??= widget.pet['size'] ?? ''; : _model.dropDownValue1 ??= '';
}
widget.pet != null
? _model.dropDownValue2 ??= widget.pet['size'] ?? ''
: _model.dropDownValue2 ??= '';
_model.dropDownValueController1 ??= _model.dropDownValueController1 ??=
FormFieldController<String>(_model.dropDownValue1 ??= ''); FormFieldController<String>(_model.dropDownValue1 ??= '');
@ -121,30 +130,10 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
_model.dispose(); _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_model.buildContext = context; _model.buildContext = context;
return Scaffold( return Scaffold(
appBar: _buildAppBar(context), appBar: _buildAppBar(context),
backgroundColor: FlutterFlowTheme.of(context).primaryBackground, backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
@ -152,14 +141,23 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
} }
PreferredSizeWidget _buildAppBar(BuildContext context) { 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) { Widget _buildTabView(BuildContext context) {
return TabViewUtil( return TabViewUtil(
context: context, context: context,
model: _model, model: _model,
labelTab1: isEditing labelTab1: _model.isEditing
? FFLocalizations.of(context) ? FFLocalizations.of(context)
.getVariableText(ptText: 'Editar', enText: 'Edit') .getVariableText(ptText: 'Editar', enText: 'Edit')
: FFLocalizations.of(context) : FFLocalizations.of(context)
@ -167,10 +165,11 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
labelTab2: FFLocalizations.of(context) labelTab2: FFLocalizations.of(context)
.getVariableText(ptText: 'Consultar', enText: 'History'), .getVariableText(ptText: 'Consultar', enText: 'History'),
controller: _model.tabBarController, controller: _model.tabBarController,
widget1: widget1: _model.isEditing
isEditing ? _buildEditForm(context) : _buildRegisterForm(context), ? _buildEditForm(context)
: _buildRegisterForm(context),
widget2: PetsHistoryScreen(), widget2: PetsHistoryScreen(),
onEditingChanged: _handleEditingChanged, onEditingChanged: onEditingChanged,
); );
} }
@ -208,7 +207,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
Padding( Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 20), padding: const EdgeInsets.fromLTRB(0, 10, 0, 20),
child: MediaUploadButtonUtil( child: MediaUploadButtonUtil(
onUploadComplete: _handleUploadComplete, onUploadComplete: _model.handleUploadComplete,
isUploading: _model.isDataUploading, isUploading: _model.isDataUploading,
uploadedFiles: _model.uploadedLocalFile, uploadedFiles: _model.uploadedLocalFile,
labelText: FFLocalizations.of(context).getVariableText( labelText: FFLocalizations.of(context).getVariableText(
@ -666,7 +665,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
Padding( Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 20), padding: const EdgeInsets.fromLTRB(0, 10, 0, 20),
child: MediaUploadButtonUtil( child: MediaUploadButtonUtil(
onUploadComplete: _handleUploadComplete, onUploadComplete: _model.handleUploadComplete,
isUploading: _model.isDataUploading, isUploading: _model.isDataUploading,
uploadedFiles: _model.uploadedLocalFile, uploadedFiles: _model.uploadedLocalFile,
labelText: FFLocalizations.of(context).getVariableText( labelText: FFLocalizations.of(context).getVariableText(