nomadcode/lib/main.dart
toki 9a39917a2c Add Firebase push notification support and Android Mattermost integration
- Android: MainActivity, AppLifecycleTracker, Firebase Messaging Service
- Android: Notification handlers (dismiss, reply, receipt delivery)
- Android: Custom push notification helper and database support
- Android: Drawable resources for notification actions
- Android: Mipmap resources with foreground/background/round icons
- iOS: Push notification service support
- Flutter: Push notification background and foreground services
- Web/Windows: Generated plugin registrant updates
- Config: Added google-services.json for Firebase
2026-03-21 15:06:19 +09:00

81 lines
2.4 KiB
Dart

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<NavigatorState>();
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<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@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'),
),
);
}
}