Merge pull request #43 from FRE-Informatica/fix/fd-827

Fix/fd 827 - Automatizar navegação e atualização do status de locais para usuários sem vínculo
This commit is contained in:
DanielYukio 2024-09-27 08:42:56 -03:00 committed by GitHub
commit 9b70003210
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 33 deletions

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:developer'; import 'dart:developer';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:hub/backend/notifications/firebase_messaging_service.dart';
import 'package:hub/shared/helpers/db_helper.dart'; import 'package:hub/shared/helpers/db_helper.dart';
import 'package:hub/shared/utils/validator_util.dart'; import 'package:hub/shared/utils/validator_util.dart';
@ -674,6 +675,7 @@ class LoginCall {
final password = AppState().passwd; final password = AppState().passwd;
final type = AppState().deviceType; final type = AppState().deviceType;
final description = AppState().deviceDescription; final description = AppState().deviceDescription;
final token = FirebaseMessagingService.getToken();
return ApiManager.instance.makeApiCall( return ApiManager.instance.makeApiCall(
callName: 'login', callName: 'login',
@ -686,6 +688,7 @@ class LoginCall {
'email': email, 'email': email,
'password': password, 'password': password,
'uuid': devUUID, 'uuid': devUUID,
'token': token,
'tipo': type, 'tipo': type,
'descricao': description, 'descricao': description,
}, },

View File

@ -56,6 +56,9 @@ class FirebaseMessagingService {
// }); // });
} }
static Future<String> getToken() async =>
await FirebaseMessaging.instance.getToken() ?? '';
Future<void> updateDeviceToken() async { Future<void> updateDeviceToken() async {
try { try {
final String? deviceToken = await _firebaseMessaging.getToken(); final String? deviceToken = await _firebaseMessaging.getToken();

View File

@ -255,6 +255,8 @@ Future<void> onMessageReceived(
break; break;
case 'enroll_cond': case 'enroll_cond':
AppState().haveLocal = true;
AppState().context!.go('/homePage');
break; break;
default: default:
break; break;

View File

@ -55,6 +55,10 @@ Future<void> initializeApp() async {
} }
Future<void> foregroundHandleMessage(RemoteMessage message) async { Future<void> foregroundHandleMessage(RemoteMessage message) async {
if (message.data['click_action'] == 'enroll_cond') {
AppState().haveLocal = true;
AppState().context!.go('/homePage');
}
if (!Platform.isIOS) { if (!Platform.isIOS) {
NotificationService.show( NotificationService.show(
title: message.notification!.title!, title: message.notification!.title!,
@ -63,7 +67,12 @@ Future<void> foregroundHandleMessage(RemoteMessage message) async {
} }
} }
Future<void> _backgroundHandleMessage(RemoteMessage message) async {} Future<void> _backgroundHandleMessage(RemoteMessage message) async {
if (message.data['click_action'] == 'enroll_cond') {
AppState().haveLocal = true;
AppState().context!.go('/homePage');
}
}
void main() async { void main() async {
await initializeApp(); await initializeApp();

View File

@ -1,32 +0,0 @@
import 'package:flutter/material.dart';
class NoConnectionScreen extends StatelessWidget {
const NoConnectionScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Sem Conexão'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.signal_wifi_off, size: 80),
const SizedBox(height: 20),
const Text(
'Você está offline. Verifique sua conexão com a internet.'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// Tente reconectar
},
child: const Text('Tentar Novamente'),
),
],
),
),
);
}
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_calls.dart';
import 'package:hub/backend/notifications/firebase_messaging_service.dart';
import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart';
@ -17,8 +18,15 @@ class ReceptionPageWidget extends StatefulWidget {
} }
class _ReceptionPageWidgetState extends State<ReceptionPageWidget> { class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
@override
void initState() {
super.initState();
FirebaseMessagingService().updateDeviceToken();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
AppState().context = context;
return ChangeNotifierProvider( return ChangeNotifierProvider(
create: (context) => ReceptionPageModel(), create: (context) => ReceptionPageModel(),
child: Scaffold( child: Scaffold(