- Backend: WebSocket plugin, chat/pricing/timer/extension/closure/notification services - Client app: ChatBloc, pricing dialog, chat screen with message status, extension/goodbye flow, history - Mitra app: MitraChatBloc, ExtensionBloc, chat screen, extension accept/reject, history - Control center: free trial, extension timeout, early end config toggles - DB migration: chat_messages, session_closures, session_extensions, customer_transactions tables Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
83 lines
2.3 KiB
Dart
83 lines
2.3 KiB
Dart
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'core/api/api_client.dart';
|
|
import 'core/auth/auth_bloc.dart';
|
|
import 'core/chat/chat_bloc.dart';
|
|
import 'core/chat/session_closure_bloc.dart';
|
|
import 'core/pairing/pairing_bloc.dart';
|
|
import 'firebase_options.dart';
|
|
import 'router.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
|
|
// Request notification permission
|
|
final messaging = FirebaseMessaging.instance;
|
|
await messaging.requestPermission();
|
|
|
|
runApp(const App());
|
|
}
|
|
|
|
class App extends StatefulWidget {
|
|
const App({super.key});
|
|
|
|
@override
|
|
State<App> createState() => _AppState();
|
|
}
|
|
|
|
class _AppState extends State<App> {
|
|
final _apiClient = ApiClient();
|
|
late final AuthBloc _authBloc;
|
|
late final GoRouter _router;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_authBloc = AuthBloc(apiClient: _apiClient)..add(AppStarted());
|
|
_router = buildRouter(_authBloc);
|
|
_registerFcmToken();
|
|
}
|
|
|
|
Future<void> _registerFcmToken() async {
|
|
// Listen for auth state, then register token
|
|
_authBloc.stream.listen((state) async {
|
|
if (state is AuthAuthenticated || state is AuthAnonymous) {
|
|
try {
|
|
final token = await FirebaseMessaging.instance.getToken();
|
|
if (token != null) {
|
|
await _apiClient.post('/api/shared/device-token', data: {'token': token});
|
|
}
|
|
} catch (_) {}
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_authBloc.close();
|
|
_router.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider.value(value: _authBloc),
|
|
BlocProvider(create: (_) => PairingBloc(apiClient: _apiClient)),
|
|
BlocProvider(create: (_) => ChatBloc(apiClient: _apiClient)),
|
|
BlocProvider(create: (_) => SessionClosureBloc(apiClient: _apiClient)),
|
|
RepositoryProvider.value(value: _apiClient),
|
|
],
|
|
child: MaterialApp.router(
|
|
title: 'Halo Bestie',
|
|
routerConfig: _router,
|
|
),
|
|
);
|
|
}
|
|
}
|