WIP
This commit is contained in:
parent
e557601a90
commit
e903683f07
|
@ -56,14 +56,14 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter android:autoVerify="true">
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<action android:name="mensagem" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="frehub" android:host="frehub.com" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<action android:name="mensagem" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
|
|
|
@ -14,6 +14,254 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart';
|
|||
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||
import 'package:hub/shared/utils/dialog_util.dart';
|
||||
|
||||
Future<void> onMessageReceived(
|
||||
Map<String, dynamic> payload, String? extra, String? handleClick) async {
|
||||
final localId = jsonDecode(payload['local']!)['CLI_ID'];
|
||||
|
||||
log('payload: $payload');
|
||||
log('extra: $extra');
|
||||
switch (handleClick) {
|
||||
case 'visit_request':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.8,
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
child: DetailsComponentWidget(
|
||||
buttons: [
|
||||
FlutterFlowIconButton(
|
||||
icon: const Icon(Icons.done),
|
||||
onPressed: () async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Aprovar Visita',
|
||||
enText: 'Approve Visit',
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Você tem certeza que deseja aprovar essa visita?',
|
||||
enText:
|
||||
'Are you sure you want to approve this visit?',
|
||||
),
|
||||
),
|
||||
backgroundColor: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
actions: [
|
||||
FFButtonWidget(
|
||||
text: FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
enText: 'No',
|
||||
ptText: 'Não',
|
||||
),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
options: FFButtonOptions(
|
||||
width: 100,
|
||||
height: 40,
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
textStyle: TextStyle(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryText,
|
||||
),
|
||||
borderSide: BorderSide(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius:
|
||||
BorderRadius.circular(10)),
|
||||
),
|
||||
FFButtonWidget(
|
||||
text: FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
enText: 'Yes',
|
||||
ptText: 'Sim',
|
||||
),
|
||||
onPressed: () async {
|
||||
log("payload: $payload");
|
||||
await answersRequest
|
||||
.call(
|
||||
context,
|
||||
payload['referencia'].toString(),
|
||||
'L',
|
||||
'Mensagem',
|
||||
payload['idVisitante'].toString(),
|
||||
)
|
||||
.then((value) {
|
||||
if (value) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
} else {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
}
|
||||
}).catchError((e) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
});
|
||||
},
|
||||
options: FFButtonOptions(
|
||||
width: 100,
|
||||
height: 40,
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
textStyle: TextStyle(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryText,
|
||||
),
|
||||
borderSide: BorderSide(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
FlutterFlowIconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () async {
|
||||
showAlertDialog(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Bloquear Visita',
|
||||
enText: 'Block Visit',
|
||||
),
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Você tem certeza que deseja bloquear essa visita?',
|
||||
enText:
|
||||
'Are you sure you want to block this visit?',
|
||||
), () async {
|
||||
await answersRequest
|
||||
.call(
|
||||
context,
|
||||
payload['referencia'].toString(),
|
||||
'B',
|
||||
'Mensagem',
|
||||
payload['idVisitante'].toString(),
|
||||
)
|
||||
.then((value) {
|
||||
if (value) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
} else {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
}
|
||||
}).catchError((e) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
labelsHashMap: Map<String, String>.from({
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Visitor',
|
||||
ptText: 'Visitante',
|
||||
): payload['nomevisita'],
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Reason',
|
||||
ptText: 'Motivo',
|
||||
): payload['motivo'],
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Message',
|
||||
ptText: 'Mensagem',
|
||||
): payload['mensagem'],
|
||||
}),
|
||||
imagePath:
|
||||
'https://freaccess.com.br/freaccess/getImage.php?cliID=${AppState().cliUUID}&atividade=getFoto&Documento=${payload['documento'] ?? ''}&tipo=E',
|
||||
statusHashMap: [
|
||||
{
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Active',
|
||||
ptText: 'Ativo',
|
||||
): FlutterFlowTheme.of(context).warning,
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
break;
|
||||
case 'access':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: AccessNotificationModalTemplateComponentWidget(
|
||||
datetime: payload['ACE_DATAHORA'].toString(),
|
||||
drive: payload['ACI_DESCRICAO'].toString(),
|
||||
id: payload['USR_TIPO'].toString() == 'O'
|
||||
? payload['USR_ID'].toString() == ''
|
||||
? '0'
|
||||
: payload['USR_ID'].toString()
|
||||
: payload['USR_DOCUMENTO'].toString() == ''
|
||||
? '0'
|
||||
: payload['USR_DOCUMENTO'].toString(),
|
||||
name: payload['PES_NOME'].toString(),
|
||||
type: payload['USR_TIPO'],
|
||||
),
|
||||
);
|
||||
});
|
||||
break;
|
||||
case 'mensagem':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.3,
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
child: MessageNotificationModalTemplateComponentWidget(
|
||||
id: localId,
|
||||
from: payload['remetente'].toString(),
|
||||
to: payload['destinatario'].toString() == 'O'
|
||||
? 'Morador'
|
||||
: 'Visitante',
|
||||
message:
|
||||
extra.toString().isEmpty ? 'Unknown' : extra.toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// showAlertDialog(AppState().context!, 'Test', 'Test', () async {});
|
||||
}
|
||||
|
||||
class NotificationService {
|
||||
static Future<void> initialize() async {
|
||||
await AwesomeNotifications().initialize(
|
||||
|
@ -40,7 +288,9 @@ class NotificationService {
|
|||
],
|
||||
debug: kDebugMode);
|
||||
|
||||
await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async {
|
||||
await AwesomeNotifications()
|
||||
.isNotificationAllowed()
|
||||
.then((isAllowed) async {
|
||||
if (!AppState().isRequestOSNotification) {
|
||||
if (!isAllowed) {
|
||||
AppState().isRequestOSNotification = true;
|
||||
|
@ -62,251 +312,7 @@ class NotificationService {
|
|||
final payload = receivedAction.payload ?? {};
|
||||
final extra = receivedAction.body;
|
||||
final handleClick = payload['click_action'];
|
||||
|
||||
final localId = jsonDecode(payload['local']!)['CLI_ID'];
|
||||
|
||||
log('payload: $payload');
|
||||
log('extra: $extra');
|
||||
switch (handleClick) {
|
||||
case 'visit_request':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.8,
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
child: DetailsComponentWidget(
|
||||
buttons: [
|
||||
FlutterFlowIconButton(
|
||||
icon: const Icon(Icons.done),
|
||||
onPressed: () async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Aprovar Visita',
|
||||
enText: 'Approve Visit',
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Você tem certeza que deseja aprovar essa visita?',
|
||||
enText:
|
||||
'Are you sure you want to approve this visit?',
|
||||
),
|
||||
),
|
||||
backgroundColor: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
actions: [
|
||||
FFButtonWidget(
|
||||
text: FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
enText: 'No',
|
||||
ptText: 'Não',
|
||||
),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
options: FFButtonOptions(
|
||||
width: 100,
|
||||
height: 40,
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
textStyle: TextStyle(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryText,
|
||||
),
|
||||
borderSide: BorderSide(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius:
|
||||
BorderRadius.circular(10)),
|
||||
),
|
||||
FFButtonWidget(
|
||||
text: FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
enText: 'Yes',
|
||||
ptText: 'Sim',
|
||||
),
|
||||
onPressed: () async {
|
||||
log("payload: $payload");
|
||||
await answersRequest
|
||||
.call(
|
||||
context,
|
||||
payload['referencia'].toString(),
|
||||
'L',
|
||||
'Mensagem',
|
||||
payload['idVisitante'].toString(),
|
||||
)
|
||||
.then((value) {
|
||||
if (value) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
} else {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
}
|
||||
}).catchError((e) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
});
|
||||
},
|
||||
options: FFButtonOptions(
|
||||
width: 100,
|
||||
height: 40,
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
textStyle: TextStyle(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryText,
|
||||
),
|
||||
borderSide: BorderSide(
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.primaryBackground,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
FlutterFlowIconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () async {
|
||||
showAlertDialog(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Bloquear Visita',
|
||||
enText: 'Block Visit',
|
||||
),
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Você tem certeza que deseja bloquear essa visita?',
|
||||
enText:
|
||||
'Are you sure you want to block this visit?',
|
||||
), () async {
|
||||
await answersRequest
|
||||
.call(
|
||||
context,
|
||||
payload['referencia'].toString(),
|
||||
'B',
|
||||
'Mensagem',
|
||||
payload['idVisitante'].toString(),
|
||||
)
|
||||
.then((value) {
|
||||
if (value) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
} else {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
}
|
||||
}).catchError((e) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
DialogUtil.errorDefault(context);
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
labelsHashMap: Map<String, String>.from({
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Visitor',
|
||||
ptText: 'Visitante',
|
||||
): payload['nomevisita'],
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Reason',
|
||||
ptText: 'Motivo',
|
||||
): payload['motivo'],
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Message',
|
||||
ptText: 'Mensagem',
|
||||
): payload['mensagem'],
|
||||
}),
|
||||
imagePath:
|
||||
'https://freaccess.com.br/freaccess/getImage.php?cliID=${AppState().cliUUID}&atividade=getFoto&Documento=${payload['documento'] ?? ''}&tipo=E',
|
||||
statusHashMap: [
|
||||
{
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Active',
|
||||
ptText: 'Ativo',
|
||||
): FlutterFlowTheme.of(context).warning,
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
break;
|
||||
case 'access':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: AccessNotificationModalTemplateComponentWidget(
|
||||
datetime: payload['ACE_DATAHORA'].toString(),
|
||||
drive: payload['ACI_DESCRICAO'].toString(),
|
||||
id: payload['USR_TIPO'].toString() == 'O'
|
||||
? payload['USR_ID'].toString() == ''
|
||||
? '0'
|
||||
: payload['USR_ID'].toString()
|
||||
: payload['USR_DOCUMENTO'].toString() == ''
|
||||
? '0'
|
||||
: payload['USR_DOCUMENTO'].toString(),
|
||||
name: payload['PES_NOME'].toString(),
|
||||
type: payload['USR_TIPO'],
|
||||
),
|
||||
);
|
||||
});
|
||||
break;
|
||||
case 'mensagem':
|
||||
showDialog(
|
||||
context: AppState().context!,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.3,
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
child: MessageNotificationModalTemplateComponentWidget(
|
||||
id: localId,
|
||||
from: payload['remetente'].toString(),
|
||||
to: payload['destinatario'].toString() == 'O'
|
||||
? 'Morador'
|
||||
: 'Visitante',
|
||||
message:
|
||||
extra.toString().isEmpty ? 'Unknown' : extra.toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// showAlertDialog(AppState().context!, 'Test', 'Test', () async {});
|
||||
onMessageReceived(payload, extra, handleClick);
|
||||
}
|
||||
|
||||
static Future<void> onNotificationCreatedMethod(
|
||||
|
|
|
@ -9,10 +9,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||
import 'package:hub/backend/api_requests/api_manager.dart';
|
||||
import 'package:hub/backend/notifications/firebase_messaging_service.dart';
|
||||
import 'package:hub/shared/utils/log_util.dart';
|
||||
import 'package:hub/backend/notifications/notification_service.dart';
|
||||
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
||||
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
||||
|
@ -51,16 +47,16 @@ Future<void> initializeApp() async {
|
|||
usePathUrlStrategy();
|
||||
}
|
||||
|
||||
Future<void> handleMessage(RemoteMessage message) async {
|
||||
Future<void> foregroundHandleMessage(RemoteMessage message) async {
|
||||
NotificationService.show(
|
||||
title: message.notification!.title!,
|
||||
body: message.notification!.body!,
|
||||
payload: Map<String, String>.from(message.data));
|
||||
}
|
||||
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
log('Background message: ${message.toMap()}');
|
||||
Future<void> _backgroundHandleMessage(RemoteMessage message) async {
|
||||
log('Handling a background message: ${message.messageId}');
|
||||
// Add your message handling logic here
|
||||
}
|
||||
|
||||
void main() async {
|
||||
|
@ -95,17 +91,15 @@ class _AppState extends State<App> {
|
|||
Future.delayed(const Duration(milliseconds: 1000),
|
||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
log('Received message: ${message.toMap()}');
|
||||
});
|
||||
FirebaseMessaging.onMessage.listen(foregroundHandleMessage);
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
log('Message opened: ${message.notification?.body}');
|
||||
onMessageReceived(message.data, '', message.data['click_action']);
|
||||
});
|
||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||
FirebaseMessaging.onBackgroundMessage(_backgroundHandleMessage);
|
||||
|
||||
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||
if (message != null) {
|
||||
log('Initial message: ${message.notification?.body}');
|
||||
_backgroundHandleMessage(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue