- keep store identity (com.mobileapp.store.ride, shorebird, firebase, fonts); old lib -> lib_old_getx - core: config/di/router(go_router)/theme/api_client(dio+tenant+bearer)/token_store(secure) - auth: repo + AuthCubit + OTP phone/otp screens; home: flutter_map (OSM placeholder, انطلق TODO) - android usesCleartextTraffic=true for http API; maps=flutter_map (no Google), state=Cubit Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../features/auth/cubit/auth_cubit.dart';
|
|
import '../features/auth/cubit/auth_state.dart';
|
|
import '../features/auth/view/phone_screen.dart';
|
|
import '../features/auth/view/otp_screen.dart';
|
|
import '../features/home/view/home_screen.dart';
|
|
|
|
GoRouter buildRouter(AuthCubit auth) {
|
|
return GoRouter(
|
|
initialLocation: '/phone',
|
|
refreshListenable: _StreamRefresh(auth.stream),
|
|
redirect: (context, state) {
|
|
final status = auth.state.status;
|
|
final loc = state.matchedLocation;
|
|
final onAuthPages = loc == '/phone' || loc == '/otp';
|
|
|
|
if (status == AuthStatus.authenticated) {
|
|
return onAuthPages ? '/home' : null;
|
|
}
|
|
if (status == AuthStatus.codeSent && loc == '/phone') return '/otp';
|
|
if (status != AuthStatus.authenticated && !onAuthPages) return '/phone';
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(path: '/phone', builder: (_, __) => const PhoneScreen()),
|
|
GoRoute(path: '/otp', builder: (_, __) => const OtpScreen()),
|
|
GoRoute(path: '/home', builder: (_, __) => const HomeScreen()),
|
|
],
|
|
);
|
|
}
|
|
|
|
class _StreamRefresh extends ChangeNotifier {
|
|
late final StreamSubscription<dynamic> _sub;
|
|
_StreamRefresh(Stream<dynamic> stream) {
|
|
notifyListeners();
|
|
_sub = stream.asBroadcastStream().listen((_) => notifyListeners());
|
|
}
|
|
@override
|
|
void dispose() {
|
|
_sub.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|