- Integrated Firebase SDK in both Flutter apps (google-services, firebase_options) - Fixed auth flow, API client, and pairing/status blocs for dev environment - Added full Flutter project scaffolds (android, ios, web, etc.) - Added phase 3 chat engine requirement document - Added bugreport zip pattern to gitignore Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
75 lines
2.9 KiB
Dart
75 lines
2.9 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'core/auth/auth_bloc.dart';
|
|
import 'features/auth/screens/welcome_screen.dart';
|
|
import 'features/auth/screens/display_name_screen.dart';
|
|
import 'features/auth/screens/register_screen.dart';
|
|
import 'features/auth/screens/otp_screen.dart';
|
|
import 'features/auth/screens/force_register_screen.dart';
|
|
import 'features/home/home_screen.dart';
|
|
import 'features/chat/screens/searching_screen.dart';
|
|
import 'features/chat/screens/bestie_found_screen.dart';
|
|
import 'features/chat/screens/no_bestie_screen.dart';
|
|
import 'features/chat/screens/session_active_screen.dart';
|
|
|
|
/// Converts a BLoC stream into a ChangeNotifier for GoRouter's refreshListenable.
|
|
class _BlocRefreshNotifier extends ChangeNotifier {
|
|
late final StreamSubscription _subscription;
|
|
|
|
_BlocRefreshNotifier(AuthBloc bloc) {
|
|
_subscription = bloc.stream.listen((_) => notifyListeners());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
GoRouter buildRouter(AuthBloc authBloc) {
|
|
return GoRouter(
|
|
initialLocation: '/welcome',
|
|
refreshListenable: _BlocRefreshNotifier(authBloc),
|
|
redirect: (context, state) {
|
|
final authState = authBloc.state;
|
|
final isAuthRoute = state.matchedLocation.startsWith('/auth') ||
|
|
state.matchedLocation == '/welcome';
|
|
|
|
// Don't redirect while loading — stay on current screen
|
|
if (authState is AuthLoading) return null;
|
|
|
|
if (authState is AuthAuthenticated || authState is AuthAnonymous) {
|
|
return isAuthRoute ? '/home' : null;
|
|
}
|
|
if (authState is AuthForceRegister) return '/auth/force-register';
|
|
if (!isAuthRoute) return '/welcome';
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(path: '/welcome', builder: (_, __) => const WelcomeScreen()),
|
|
GoRoute(path: '/auth/display-name', builder: (_, __) => const DisplayNameScreen()),
|
|
GoRoute(path: '/auth/register', builder: (_, __) => const RegisterScreen()),
|
|
GoRoute(path: '/auth/otp', builder: (context, state) => OtpScreen(phone: state.extra as String)),
|
|
GoRoute(path: '/auth/force-register', builder: (_, __) => const ForceRegisterScreen()),
|
|
GoRoute(path: '/home', builder: (_, __) => const HomeScreen()),
|
|
GoRoute(path: '/chat/searching', builder: (_, __) => const SearchingScreen()),
|
|
GoRoute(path: '/chat/found', builder: (context, state) {
|
|
final extra = state.extra as Map<String, dynamic>;
|
|
return BestieFoundScreen(
|
|
sessionId: extra['sessionId'] as String,
|
|
mitraName: extra['mitraName'] as String,
|
|
);
|
|
}),
|
|
GoRoute(path: '/chat/no-bestie', builder: (_, __) => const NoBestieScreen()),
|
|
GoRoute(path: '/chat/session/:sessionId', builder: (context, state) {
|
|
return SessionActiveScreen(
|
|
sessionId: state.pathParameters['sessionId']!,
|
|
mitraName: state.extra as String? ?? 'Bestie',
|
|
);
|
|
}),
|
|
],
|
|
);
|
|
}
|