الباك إند: - تعيين أول أدمن صار يُنشئ المستخدم إن لم يوجد — كان يشترط دخولاً سابقاً، وهي بيضة ودجاجة تمنع الدخول إلى لوحة أي مستأجر جديد أصلاً. - OTP_DEV_MODE كان يفشل مفتوحاً (`!== 'false'`): غياب المتغيّر أو خطأ مطبعي يترك الإنتاج برمز ثابت يفتح كل حساب، ويحرس السحب المالي كذلك. صار `=== 'true'` في الإعداد وفي قارئَيه، مع تحذير عند الإقلاع. - N2: التحقّق من اللوغو عند الرفع (PNG/JPEG · 512+ · مربّع · سقف 5MB) عبر قراءة الترويسة بلا اعتمادية — بدل اكتشاف أيقونة ممطوطة بعد النشر. N3: السكربت يولّد build_config.dart بأعلام const (طبقات docs/22 §1.5)، ويضبط bundle IDs واسم التطبيق والأيقونات/splash، و--build يشغّل Shorebird. فلاتر: - docs/23: قانون مُلزِم للتطبيقين (البنية · Cubit · طبقة الشبكة · الأعلام). - السائق: أُزيل Dart القديم (GetX) مع الإبقاء على الأصيل والإضافات وشهادات التوقيع وShorebird وFirebase الخاص به، وأُعيد هيكلته مطابقاً للراكب. - طبقة الشبكة ترسل x-device-id وتجدّد التوكن عند 401 مرة واحدة فقط. - الحزم موحّدة بين التطبيقين، والـAPI https حصراً في الاثنين. Co-Authored-By: Claude Fable 5 <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();
|
|
}
|
|
}
|