213 lines
7.3 KiB
Dart
213 lines
7.3 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
|
import 'package:hub/app_state.dart';
|
|
import 'package:hub/firebase_options.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
|
import 'package:hub/flutter_flow/internationalization.dart';
|
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
|
import 'package:hub/shared/utils/notification_util.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:responsive_framework/responsive_framework.dart';
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
@pragma('vm:entry-point')
|
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
if (!isFlutterLocalNotificationsInitialized)
|
|
await setupFlutterNotifications();
|
|
if (!Firebase.apps.isNotEmpty)
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform);
|
|
if (message.data.isNotEmpty) {
|
|
log('Handling a background message ${message.messageId}');
|
|
log('Message data: ${message.data}');
|
|
showFlutterNotification(message);
|
|
}
|
|
log('Handling a background message ${message.messageId}');
|
|
}
|
|
|
|
late AndroidNotificationChannel channel;
|
|
bool isFlutterLocalNotificationsInitialized = false;
|
|
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
|
|
|
|
late final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
|
|
|
|
Future<void> setupFlutterNotifications() async {
|
|
if (isFlutterLocalNotificationsInitialized) return;
|
|
|
|
channel = const AndroidNotificationChannel(
|
|
'high_importance_channel', // id
|
|
'High Importance Notifications', // title
|
|
description:
|
|
'This channel is used for important notifications.', // description
|
|
importance: Importance.high,
|
|
);
|
|
|
|
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
|
|
await flutterLocalNotificationsPlugin
|
|
.resolvePlatformSpecificImplementation<
|
|
AndroidFlutterLocalNotificationsPlugin>()
|
|
?.createNotificationChannel(channel);
|
|
flutterLocalNotificationsPlugin.initialize(
|
|
InitializationSettings(
|
|
android: const AndroidInitializationSettings('ic_launcher'),
|
|
iOS: DarwinInitializationSettings(onDidReceiveLocalNotification:
|
|
(int id, String? title, String? body, String? payload) async {
|
|
log('Test');
|
|
}),
|
|
),
|
|
onDidReceiveBackgroundNotificationResponse: (details) => log('Test'),
|
|
onDidReceiveNotificationResponse: (details) => log('Test'),
|
|
);
|
|
|
|
isFlutterLocalNotificationsInitialized = true;
|
|
}
|
|
|
|
Future<void> initializeFirebase() async {}
|
|
|
|
Future<void> initializeApp() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
// await initializeFirebase();
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
|
await setupFlutterNotifications();
|
|
setUrlStrategy(const PathUrlStrategy());
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
if (kDebugMode) {
|
|
log("Aplicativo em Debug Mode, crashlytics desabilitado!");
|
|
} else {
|
|
final crashlyticsInstance = FirebaseCrashlytics.instance;
|
|
if (crashlyticsInstance.isCrashlyticsCollectionEnabled) {
|
|
FlutterError.onError = crashlyticsInstance.recordFlutterError;
|
|
}
|
|
}
|
|
|
|
await FlutterFlowTheme.initialize();
|
|
await FFLocalizations.initialize();
|
|
final appState = AppState();
|
|
await appState.initializePersistedState();
|
|
GoRouter.optionURLReflectsImperativeAPIs = true;
|
|
usePathUrlStrategy();
|
|
}
|
|
|
|
void main() async {
|
|
await initializeApp();
|
|
runApp(const App());
|
|
}
|
|
|
|
class App extends StatefulWidget {
|
|
const App({super.key});
|
|
@override
|
|
State<App> createState() => _AppState();
|
|
static _AppState of(BuildContext context) =>
|
|
context.findAncestorStateOfType<_AppState>()!;
|
|
}
|
|
|
|
class _AppState extends State<App> {
|
|
Locale? _locale = FFLocalizations.getStoredLocale();
|
|
ThemeMode _themeMode = FlutterFlowTheme.themeMode;
|
|
late AppStateNotifier _appStateNotifier;
|
|
late GoRouter _router;
|
|
bool displaySplashImage = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
|
|
|
|
_appStateNotifier = AppStateNotifier.instance;
|
|
_router = createRouter(_appStateNotifier);
|
|
Future.delayed(const Duration(milliseconds: 1000),
|
|
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
|
}
|
|
|
|
void setLocale(String language) {
|
|
setState(() => _locale = createLocale(language));
|
|
FFLocalizations.storeLocale(language);
|
|
}
|
|
|
|
void setThemeMode(ThemeMode mode) {
|
|
setState(() {
|
|
_themeMode = mode;
|
|
FlutterFlowTheme.saveThemeMode(mode);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (_) => AppState()),
|
|
],
|
|
child: MaterialApp.router(
|
|
title: 'FREHub',
|
|
builder: (context, widget) => ResponsiveBreakpoints.builder(
|
|
child: BouncingScrollWrapper.builder(context, widget!),
|
|
breakpoints: [
|
|
const Breakpoint(start: 0, end: 450, name: MOBILE),
|
|
const Breakpoint(start: 451, end: 800, name: TABLET),
|
|
const Breakpoint(start: 801, end: 1920, name: DESKTOP),
|
|
const Breakpoint(start: 1921, end: double.infinity, name: '4K'),
|
|
],
|
|
),
|
|
localizationsDelegates: const [
|
|
FFLocalizationsDelegate(),
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
locale: _locale,
|
|
supportedLocales: const [
|
|
Locale('pt'),
|
|
Locale('en'),
|
|
],
|
|
theme: ThemeData(
|
|
brightness: Brightness.light,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
thumbVisibility: WidgetStateProperty.all(false),
|
|
interactive: false,
|
|
thumbColor: WidgetStateProperty.resolveWith((states) {
|
|
if (states.contains(WidgetState.dragged)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
if (states.contains(WidgetState.hovered)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
brightness: Brightness.dark,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
thumbVisibility: WidgetStateProperty.all(false),
|
|
interactive: false,
|
|
thumbColor: WidgetStateProperty.resolveWith((states) {
|
|
if (states.contains(WidgetState.dragged)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
if (states.contains(WidgetState.hovered)) {
|
|
return const Color(0xff1aab5f);
|
|
}
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
themeMode: _themeMode,
|
|
routerConfig: _router,
|
|
),
|
|
);
|
|
}
|
|
}
|