163 lines
5.3 KiB
Dart
163 lines
5.3 KiB
Dart
import 'package:f_r_e_hub/backend/api_requests/api_calls.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'firebase_options.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
|
import 'flutter_flow/flutter_flow_theme.dart';
|
|
import 'flutter_flow/flutter_flow_util.dart';
|
|
import 'flutter_flow/internationalization.dart';
|
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
FirebaseAnalytics analyticsInstance = FirebaseAnalytics.instance;
|
|
analyticsInstance.logEvent(
|
|
name: 'test_event',
|
|
parameters: <String, Object>{
|
|
'string': 'test',
|
|
'int': 42,
|
|
'long': 12345678910,
|
|
'double': 42.0,
|
|
'boolAsString': true.toString(),
|
|
},
|
|
);
|
|
|
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
|
var initializationSettingsAndroid =
|
|
const AndroidInitializationSettings('mipmap/ic_launcher');
|
|
var initializationSettingsIOS = const DarwinInitializationSettings(
|
|
requestAlertPermission: true,
|
|
requestBadgePermission: true,
|
|
requestSoundPermission: true,
|
|
);
|
|
var initializationSettings = InitializationSettings(
|
|
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
|
|
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
|
RemoteNotification? notification = message.notification;
|
|
AndroidNotification? android = message.notification?.android;
|
|
if (notification != null && android != null) {
|
|
_flutterLocalNotificationsPlugin.show(
|
|
notification.hashCode,
|
|
notification.title,
|
|
notification.body,
|
|
const NotificationDetails(
|
|
android: AndroidNotificationDetails(
|
|
'visitRequest',
|
|
'Visitas',
|
|
channelDescription: 'Solicitação de visita',
|
|
importance: Importance.max,
|
|
priority: Priority.high,
|
|
icon: 'mipmap/ic_launcher',
|
|
),
|
|
),
|
|
);
|
|
}
|
|
});
|
|
GoRouter.optionURLReflectsImperativeAPIs = true;
|
|
usePathUrlStrategy();
|
|
await FlutterFlowTheme.initialize();
|
|
await FFLocalizations.initialize();
|
|
final appState = FFAppState();
|
|
await appState.initializePersistedState();
|
|
runApp(ChangeNotifierProvider(
|
|
create: (context) => appState,
|
|
child: const MyApp(),
|
|
));
|
|
}
|
|
|
|
// Inicialização do plugin de notificações locais
|
|
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
// Manipulador de mensagens em segundo plano
|
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
// Certifique-se de inicializar o Firebase dentro do manipulador
|
|
await Firebase.initializeApp();
|
|
print("Handling a background message: ${message.messageId}");
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
|
|
static _MyAppState of(BuildContext context) =>
|
|
context.findAncestorStateOfType<_MyAppState>()!;
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
Locale? _locale = FFLocalizations.getStoredLocale();
|
|
ThemeMode _themeMode = FlutterFlowTheme.themeMode;
|
|
late AppStateNotifier _appStateNotifier;
|
|
late GoRouter _router;
|
|
bool displaySplashImage = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_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 MaterialApp.router(
|
|
title: 'FREHub',
|
|
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) {
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
brightness: Brightness.dark,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
thumbVisibility: WidgetStateProperty.all(false),
|
|
interactive: false,
|
|
thumbColor: WidgetStateProperty.resolveWith((states) {
|
|
return const Color(0xff1aab5f);
|
|
}),
|
|
),
|
|
),
|
|
themeMode: _themeMode,
|
|
routerConfig: _router,
|
|
);
|
|
}
|
|
}
|