import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'services/push_notification_background.dart'; import 'services/push_notification_service.dart'; final _navigatorKey = GlobalKey(); void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); final pushService = PushNotificationService(); pushService.init(); runApp(MyApp(pushService: pushService)); } class MyApp extends StatelessWidget { final PushNotificationService pushService; const MyApp({super.key, required this.pushService}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Mattermost', navigatorKey: _navigatorKey, theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'Mattermost'), builder: (context, child) { // 알림 탭 시 네비게이션 콜백 등록 pushService.onNavigateToChannel = (serverUrl, channelId) { // TODO: 채널 화면으로 이동 // _navigatorKey.currentState?.pushNamed( // '/channel', // arguments: {'serverUrl': serverUrl, 'channelId': channelId}, // ); print('[Nav] Navigate to channel: $channelId on $serverUrl'); }; pushService.onNavigateToThread = (serverUrl, rootId) { // TODO: 스레드 화면으로 이동 // _navigatorKey.currentState?.pushNamed( // '/thread', // arguments: {'serverUrl': serverUrl, 'rootId': rootId}, // ); print('[Nav] Navigate to thread: $rootId on $serverUrl'); }; return child!; }, ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: const Center( child: Text('Mattermost Flutter'), ), ); } }