WIP
This commit is contained in:
parent
d0b59b0b0a
commit
2ac27d7db7
|
@ -47,8 +47,12 @@
|
||||||
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||||
android:resource="@drawable/launch_background"
|
android:resource="@drawable/launch_background"
|
||||||
/>
|
/>
|
||||||
<!-- Deep linking -->
|
|
||||||
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
<!-- <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -64,7 +68,7 @@
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter> -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,4 +98,10 @@
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
<queries>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||||
|
<data android:mimeType="text/plain"/>
|
||||||
|
</intent>
|
||||||
|
</queries>
|
||||||
</manifest>
|
</manifest>
|
|
@ -3,17 +3,21 @@ import 'dart:developer';
|
||||||
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';
|
||||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_web_plugins/url_strategy.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/backend/notifications/firebase_messaging_service.dart';
|
||||||
import 'package:hub/backend/notifications/notification_service.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_theme.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
||||||
import 'package:hub/flutter_flow/internationalization.dart';
|
import 'package:hub/flutter_flow/internationalization.dart';
|
||||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||||
|
import 'package:hub/shared/utils/log_util.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:responsive_framework/responsive_framework.dart';
|
import 'package:responsive_framework/responsive_framework.dart';
|
||||||
|
|
||||||
|
@ -28,8 +32,7 @@ Future<void> initializeApp() async {
|
||||||
await appState.initializePersistedState();
|
await appState.initializePersistedState();
|
||||||
|
|
||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
await FirebaseMessagingService().initNotifications();
|
// await NotificationService.initialize();
|
||||||
await NotificationService.initialize();
|
|
||||||
|
|
||||||
setUrlStrategy(const PathUrlStrategy());
|
setUrlStrategy(const PathUrlStrategy());
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
|
@ -48,6 +51,18 @@ Future<void> initializeApp() async {
|
||||||
usePathUrlStrategy();
|
usePathUrlStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> handleMessage(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()}');
|
||||||
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
await initializeApp();
|
await initializeApp();
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
|
@ -67,6 +82,32 @@ class _AppState extends State<App> {
|
||||||
late AppStateNotifier _appStateNotifier;
|
late AppStateNotifier _appStateNotifier;
|
||||||
late GoRouter _router;
|
late GoRouter _router;
|
||||||
bool displaySplashImage = true;
|
bool displaySplashImage = true;
|
||||||
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
|
||||||
|
|
||||||
|
Future<void> updateDeviceToken() async {
|
||||||
|
try {
|
||||||
|
final String? deviceToken = await _firebaseMessaging.getToken();
|
||||||
|
|
||||||
|
if (deviceToken != null) {
|
||||||
|
AppState().token = deviceToken;
|
||||||
|
|
||||||
|
final ApiCallResponse? response = await PhpGroup.updToken.call(
|
||||||
|
token: AppState().token,
|
||||||
|
devid: AppState().devUUID,
|
||||||
|
useruuid: AppState().userUUID);
|
||||||
|
|
||||||
|
if (PhpGroup.updToken.error((response?.jsonBody ?? '')) == false) {
|
||||||
|
log('Token Atualizado com Sucesso!');
|
||||||
|
} else {
|
||||||
|
log('Falha ao Atualizar Token: ${response?.jsonBody}');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log('Falha ao Pegar Token do Firebase');
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
LogUtil.requestAPIFailed("updToken.php", "", "Atualizar Token", e, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -79,7 +120,33 @@ class _AppState extends State<App> {
|
||||||
_router = createRouter(_appStateNotifier);
|
_router = createRouter(_appStateNotifier);
|
||||||
Future.delayed(const Duration(milliseconds: 1000),
|
Future.delayed(const Duration(milliseconds: 1000),
|
||||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
||||||
|
|
||||||
|
_firebaseMessaging.requestPermission();
|
||||||
|
// _firebaseMessaging.pluginConstants;
|
||||||
|
|
||||||
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||||
|
log('Received message: ${message.toMap()}');
|
||||||
|
});
|
||||||
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||||
|
log('Message opened: ${message.notification?.body}');
|
||||||
|
});
|
||||||
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||||
|
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||||
|
if (message != null) {
|
||||||
|
log('Initial message: ${message.notification?.body}');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_firebaseMessaging.onTokenRefresh.listen((token) => updateDeviceToken);
|
||||||
|
|
||||||
|
getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getToken() async {
|
||||||
|
String? token = await _firebaseMessaging.getToken();
|
||||||
|
log('Token: $token');
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Future<void> showCustomTrackingDialog(BuildContext context) async {
|
// Future<void> showCustomTrackingDialog(BuildContext context) async {
|
||||||
// await showDialog<void>(
|
// await showDialog<void>(
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
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/backend/notifications/firebase_messaging_service.dart';
|
||||||
|
import 'package:hub/backend/notifications/notification_service.dart';
|
||||||
import 'package:hub/backend/schema/enums/enums.dart';
|
import 'package:hub/backend/schema/enums/enums.dart';
|
||||||
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
||||||
import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart';
|
import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart';
|
||||||
|
@ -14,6 +17,7 @@ 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';
|
||||||
import 'package:hub/pages/home_page/home_page_model.dart';
|
import 'package:hub/pages/home_page/home_page_model.dart';
|
||||||
import 'package:hub/shared/utils/dialog_util.dart';
|
import 'package:hub/shared/utils/dialog_util.dart';
|
||||||
|
import 'package:hub/shared/utils/log_util.dart';
|
||||||
import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart';
|
import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart';
|
||||||
|
|
||||||
class HomePageWidget extends StatefulWidget {
|
class HomePageWidget extends StatefulWidget {
|
||||||
|
@ -118,8 +122,6 @@ class _HomePageWidgetState extends State<HomePageWidget> {
|
||||||
_model.updateOnChange = true;
|
_model.updateOnChange = true;
|
||||||
|
|
||||||
() async {
|
() async {
|
||||||
await FirebaseMessagingService().updateDeviceToken();
|
|
||||||
|
|
||||||
if (AppState().cliUUID.isEmpty) {
|
if (AppState().cliUUID.isEmpty) {
|
||||||
await processLocals();
|
await processLocals();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue