feat(apps): الدراور وطبقتا الميزات والإشعارات — المرحلة 6
## طبقتا الميزات مُطبَّقتان معاً
AppDrawer يفحص: Features.wallet && context.tenantHas('wallet')
- Features.x ثابت const: يقرّر ما يُبنى في الـbinary. إطفاؤه يحذف الكود
فلا يُستخرج (docs/23 §5)
- tenantHas من GET /tenant/config/:slug: يقرّر ما يُعرض ممّا بُني حسب اشتراك
المستأجر (docs/38 §10)
هذا هو ربط lite/pro/max عملياً. TenantCubit يعرض النسخة المخزّنة فوراً ثم
يحدّثها: إقلاع بلا إنترنت يعرض الميزات المعروفة آخر مرة لا شاشة فارغة.
## الشاشات
الدراور · تعديل الحساب · سجلّ الرحلات · الإعدادات (مظهر + لغة) · المساعدة.
الرقم في تعديل الحساب معطّل مع سبب معروض لا مخفي: هو هوية الحساب على الخادم
وتغييره يعني حساباً آخر (docs/38 §1).
## الإشعارات
PushService معزول — الملف الوحيد الذي يعرف Firebase. التسجيل بعد إثبات
الجلسة عبر خطّاف في SessionCubit، ومع اشتراك onTokenRefresh: بدونه تتوقّف
الإشعارات بصمت بعد أسابيع. الإعداد الأصلي كان جاهزاً مسبقاً.
## تصحيحات بنيوية كشفها فحص آلي
docs/23 §1 يمنع أن تستورد ميزة من أخرى — وكانت خمس مخالفات:
1. features/history أُدمجت في features/trip — السجلّ جزء من ميزة الرحلة
2. AppDrawer صعد إلى core/ui — هيكل تطبيق لا ميزة
3. AuthFailure → core/api/api_failure.dart، ومترجمه → core/ui/failure_text.dart
4. AuthHeader → core/ui/form_header.dart
5. ProfileRepository مستقلّ عن AuthRepository: تعديل الملف ليس مصادقة
flutter analyze نظيف · الراكب 98 ملف/7,497 سطر · السائق 95 ملف/6,931 سطر.
فحوص آلية نظيفة: صفر استيراد بين ميزتين · core يستورد features من di و
router وحدهما · Firebase و intaleq_maps و geolocator و socket_io كلٌّ معزول.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
66e28acc58
commit
096acae74e
@@ -1,6 +1,7 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
import 'api_exception.dart';
|
||||
|
||||
/// عميل map-saas — **منفصل تماماً** عن `ApiClient`.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
import '../storage/token_store.dart';
|
||||
|
||||
import 'api_exception.dart';
|
||||
|
||||
import 'auth_interceptor.dart';
|
||||
|
||||
/// الواجهة الوحيدة للخادم. لا تُنشأ `Dio` في أي مكان آخر.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'api_exception.dart';
|
||||
|
||||
/// سبب الفشل كـ**رمز** لا كنصّ.
|
||||
///
|
||||
/// docs/23 §3 يقول إن الـCubit يحوّل خطأ الشبكة إلى رسالة عربية؛ وdocs/26 §4
|
||||
/// (الأحدث، وهو الذي «يفعّل قاعدة docs/23 §2 التي كانت بلا أداة») يوجب مرور
|
||||
/// كل نص مرئي بطبقة الترجمة. والـCubit لا يعرف `BuildContext` (docs/23 §3).
|
||||
/// الجمع بينها: الـCubit يُصدر الرمز، والواجهة تترجمه سطراً واحداً — فتبقى
|
||||
/// الشاشة بلا منطق، والنص بلغتين.
|
||||
enum AuthFailure {
|
||||
/// رمز خاطئ أو منتهي الصلاحية.
|
||||
invalidCode,
|
||||
|
||||
/// تجاوز عدد المحاولات — الخادم يُبطل الرمز فوراً (docs/38 §2).
|
||||
tooManyAttempts,
|
||||
|
||||
/// تجاوز حدّ طلب الرمز: ثلاثة كل خمس دقائق.
|
||||
rateLimited,
|
||||
|
||||
network,
|
||||
timeout,
|
||||
server,
|
||||
}
|
||||
|
||||
extension AuthFailureX on ApiException {
|
||||
AuthFailure toAuthFailure() {
|
||||
if (isRateLimited) return AuthFailure.rateLimited;
|
||||
if (kind == ApiErrorKind.network) return AuthFailure.network;
|
||||
if (kind == ApiErrorKind.timeout) return AuthFailure.timeout;
|
||||
if (isUnauthorized) {
|
||||
// الخادم يفرّق بين «رمز خاطئ» و«محاولات كثيرة» بالنصّ وحده.
|
||||
return message.contains('Too many')
|
||||
? AuthFailure.tooManyAttempts
|
||||
: AuthFailure.invalidCode;
|
||||
}
|
||||
return AuthFailure.server;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ import 'dart:async';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../build_config.dart';
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
import '../storage/token_store.dart';
|
||||
|
||||
/// يثبّت ترويسات كل طلب، ويجدّد التوكن **استباقياً** قبل انتهائه.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../build_config.dart';
|
||||
|
||||
import 'tokens.dart';
|
||||
|
||||
import 'tripz_colors.dart';
|
||||
|
||||
import 'typography.dart';
|
||||
|
||||
/// دالة بناء الثيم الوحيدة (docs/26 §4): مدخلان لا ثالث لهما.
|
||||
|
||||
@@ -1,28 +1,57 @@
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../features/auth/cubit/login_cubit.dart';
|
||||
|
||||
import '../features/auth/data/auth_repository.dart';
|
||||
import '../features/profile/data/profile_repository.dart';
|
||||
|
||||
import '../features/rating/cubit/rating_cubit.dart';
|
||||
|
||||
import '../features/rating/data/rating_repository.dart';
|
||||
|
||||
import '../features/settings/cubit/settings_cubit.dart';
|
||||
|
||||
import '../features/trip/cubit/history_cubit.dart';
|
||||
|
||||
import '../features/trip/cubit/duty_cubit.dart';
|
||||
|
||||
import '../features/trip/data/history_repository.dart';
|
||||
|
||||
import '../features/trip/data/maps_repository.dart';
|
||||
|
||||
import '../features/trip/data/trip_repository.dart';
|
||||
|
||||
import '../features/wallet/cubit/payout_cubit.dart';
|
||||
import '../features/wallet/cubit/wallet_cubit.dart';
|
||||
|
||||
import '../features/wallet/data/wallet_repository.dart';
|
||||
import '../features/trip/data/maps_repository.dart';
|
||||
import '../features/trip/data/trip_repository.dart';
|
||||
|
||||
import 'api/antlaq_api.dart';
|
||||
|
||||
import 'api/api_client.dart';
|
||||
import 'location/location_service.dart';
|
||||
import 'realtime/realtime_service.dart';
|
||||
import 'session/session_cubit.dart';
|
||||
|
||||
import 'build_config.dart';
|
||||
|
||||
import 'location/location_service.dart';
|
||||
|
||||
import 'notifications/push_service.dart';
|
||||
|
||||
import 'realtime/realtime_service.dart';
|
||||
|
||||
import 'session/session_cubit.dart';
|
||||
|
||||
import 'storage/token_store.dart';
|
||||
|
||||
import 'tenant/tenant_cubit.dart';
|
||||
|
||||
final sl = GetIt.instance;
|
||||
|
||||
/// نقطة الإقفال الوحيدة (docs/23 §5): الميزة المطفأة **لا تُسجَّل**، بدل
|
||||
@@ -52,7 +81,10 @@ Future<void> setupInjector() async {
|
||||
);
|
||||
|
||||
sl.registerSingleton<AuthRepository>(AuthRepository(sl(), sl()));
|
||||
sl.registerSingleton<SessionCubit>(SessionCubit(sl()));
|
||||
sl.registerSingleton<ProfileRepository>(ProfileRepository(sl()));
|
||||
sl.registerSingleton<SessionCubit>(
|
||||
SessionCubit(sl(), onAuthenticated: () => sl<PushService>().register()),
|
||||
);
|
||||
|
||||
// تدفّق الدخول قصير العمر: نسخة جديدة لكل دخول، لا نسخة واحدة أبدية.
|
||||
sl.registerFactory<LoginCubit>(() => LoginCubit(sl(), sl()));
|
||||
@@ -64,6 +96,12 @@ Future<void> setupInjector() async {
|
||||
sl.registerSingleton<LocationService>(LocationService());
|
||||
sl.registerSingleton<RealtimeService>(RealtimeService(tokens));
|
||||
|
||||
sl.registerSingleton<TenantCubit>(TenantCubit(sl(), prefs));
|
||||
sl.registerSingleton<PushService>(PushService(sl()));
|
||||
|
||||
sl.registerSingleton<HistoryRepository>(HistoryRepository(sl()));
|
||||
sl.registerFactory<HistoryCubit>(() => HistoryCubit(sl()));
|
||||
|
||||
sl.registerSingleton<RatingRepository>(RatingRepository(sl()));
|
||||
sl.registerFactory<RatingCubit>(() => RatingCubit(sl()));
|
||||
|
||||
|
||||
@@ -161,5 +161,32 @@
|
||||
"payoutDone": "تم إرسال طلب السحب",
|
||||
"payoutFailed": "تعذّر إتمام السحب",
|
||||
"payoutInsufficient": "الرصيد لا يكفي",
|
||||
"payoutHistory": "طلبات السحب"
|
||||
"payoutHistory": "طلبات السحب",
|
||||
"menuTitle": "القائمة",
|
||||
"menuProfile": "حسابي",
|
||||
"menuTrips": "رحلاتي",
|
||||
"menuWallet": "المحفظة",
|
||||
"menuEarnings": "أرباحي",
|
||||
"menuSettings": "الإعدادات",
|
||||
"menuSupport": "المساعدة",
|
||||
"menuAbout": "عن التطبيق",
|
||||
"menuLogout": "تسجيل الخروج",
|
||||
"menuLogoutConfirm": "هل تريد الخروج من حسابك؟",
|
||||
"historyTitle": "رحلاتي",
|
||||
"historyEmpty": "لا رحلات بعد — اتصل لتصلك الطلبات",
|
||||
"historyStatusCompleted": "مكتملة",
|
||||
"historyStatusCancelled": "ملغاة",
|
||||
"historyStatusLive": "جارية",
|
||||
"profileEditTitle": "تعديل الحساب",
|
||||
"profilePhone": "رقم الهاتف",
|
||||
"profilePhoneLocked": "لا يمكن تغيير الرقم — هو هوية حسابك",
|
||||
"profileSaved": "حُفظت التعديلات",
|
||||
"supportTitle": "المساعدة",
|
||||
"supportFaq": "الأسئلة الشائعة",
|
||||
"supportContact": "تواصل معنا",
|
||||
"supportWhatsapp": "مراسلة عبر واتساب",
|
||||
"aboutVersion": "الإصدار",
|
||||
"notifTitle": "الإشعارات",
|
||||
"notifEnable": "تفعيل الإشعارات",
|
||||
"notifDenied": "الإشعارات موقوفة من إعدادات النظام"
|
||||
}
|
||||
@@ -161,5 +161,32 @@
|
||||
"payoutDone": "Withdrawal request sent",
|
||||
"payoutFailed": "Withdrawal failed",
|
||||
"payoutInsufficient": "Insufficient balance",
|
||||
"payoutHistory": "Withdrawal requests"
|
||||
"payoutHistory": "Withdrawal requests",
|
||||
"menuTitle": "Menu",
|
||||
"menuProfile": "Account",
|
||||
"menuTrips": "My trips",
|
||||
"menuWallet": "Wallet",
|
||||
"menuEarnings": "Earnings",
|
||||
"menuSettings": "Settings",
|
||||
"menuSupport": "Help",
|
||||
"menuAbout": "About",
|
||||
"menuLogout": "Sign out",
|
||||
"menuLogoutConfirm": "Sign out of your account?",
|
||||
"historyTitle": "My trips",
|
||||
"historyEmpty": "No trips yet — go online to receive requests",
|
||||
"historyStatusCompleted": "Completed",
|
||||
"historyStatusCancelled": "Cancelled",
|
||||
"historyStatusLive": "In progress",
|
||||
"profileEditTitle": "Edit account",
|
||||
"profilePhone": "Phone number",
|
||||
"profilePhoneLocked": "Your number can't be changed — it identifies your account",
|
||||
"profileSaved": "Changes saved",
|
||||
"supportTitle": "Help",
|
||||
"supportFaq": "FAQ",
|
||||
"supportContact": "Contact us",
|
||||
"supportWhatsapp": "Message on WhatsApp",
|
||||
"aboutVersion": "Version",
|
||||
"notifTitle": "Notifications",
|
||||
"notifEnable": "Enable notifications",
|
||||
"notifDenied": "Notifications are disabled in system settings"
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../api/api_client.dart';
|
||||
|
||||
import '../api/api_exception.dart';
|
||||
|
||||
/// إشعارات FCM — **الطبقة الوحيدة التي تعرف Firebase**.
|
||||
///
|
||||
/// عقد الخادم نقطة واحدة: `POST /notifications/token { token, platform }`
|
||||
/// (docs/38 §11). لا نقطة سرد إشعارات، فلا شاشة «صندوق إشعارات» تُبنى على
|
||||
/// وهم — ما يصل يصل من النظام.
|
||||
///
|
||||
/// الإعداد الأصلي جاهز مسبقاً: `google-services.json` و
|
||||
/// `GoogleService-Info.plist` منقولان مع الطبقة الأصلية، و`build.gradle`
|
||||
/// يطبّق `com.google.gms.google-services` أصلاً.
|
||||
class PushService {
|
||||
PushService(this._api);
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
/// يُنادى **بعد** الدخول: التسجيل يربط الجهاز بالمستخدم، فقبل الجلسة
|
||||
/// لا معنى له.
|
||||
Future<void> register() async {
|
||||
try {
|
||||
await Firebase.initializeApp();
|
||||
final messaging = FirebaseMessaging.instance;
|
||||
|
||||
final settings = await messaging.requestPermission();
|
||||
if (settings.authorizationStatus == AuthorizationStatus.denied) return;
|
||||
|
||||
final token = await messaging.getToken();
|
||||
if (token != null) await _send(token);
|
||||
|
||||
// الرمز يُدوَّر من Google دورياً — بلا هذا الاشتراك تتوقّف الإشعارات
|
||||
// بصمت بعد أسابيع.
|
||||
messaging.onTokenRefresh.listen(_send);
|
||||
} catch (_) {
|
||||
// غياب الإشعارات لا يمنع استعمال التطبيق — لا يُسقط الإقلاع.
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _send(String token) async {
|
||||
try {
|
||||
await _api.post<Map<String, dynamic>>(
|
||||
'/notifications/token',
|
||||
body: {
|
||||
'token': token,
|
||||
'platform': defaultTargetPlatformName,
|
||||
},
|
||||
);
|
||||
} on ApiException {
|
||||
// يُعاد في الإقلاع التالي.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// المنصّة كما يتوقّعها الخادم — تُقرأ من المنصّة الفعلية لا من عَلَم بناء.
|
||||
String get defaultTargetPlatformName => switch (defaultTargetPlatform) {
|
||||
TargetPlatform.iOS => 'ios',
|
||||
TargetPlatform.android => 'android',
|
||||
_ => 'unknown',
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:socket_io_client/socket_io_client.dart' as io;
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
import '../storage/token_store.dart';
|
||||
|
||||
/// أحداث الخادم كما هي في `backend-archive/src/realtime` (docs/38 §9).
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'session/session_cubit.dart';
|
||||
import 'session/session_state.dart';
|
||||
import '../features/auth/view/login_page.dart';
|
||||
import '../features/auth/view/profile_page.dart';
|
||||
|
||||
import '../features/profile/view/profile_edit_page.dart';
|
||||
|
||||
import '../features/profile/view/profile_setup_page.dart';
|
||||
|
||||
import '../features/rating/data/rating_repository.dart';
|
||||
|
||||
import '../features/rating/view/rating_page.dart';
|
||||
import '../features/trip/view/duty_page.dart';
|
||||
import '../features/wallet/view/earnings_page.dart';
|
||||
|
||||
import '../features/settings/view/settings_page.dart';
|
||||
|
||||
import '../features/splash/view/splash_page.dart';
|
||||
|
||||
import '../features/support/view/support_page.dart';
|
||||
|
||||
import '../features/trip/view/history_page.dart';
|
||||
|
||||
import '../features/trip/view/duty_page.dart';
|
||||
|
||||
import '../features/wallet/view/earnings_page.dart';
|
||||
|
||||
import 'di.dart';
|
||||
|
||||
import 'session/session_cubit.dart';
|
||||
|
||||
import 'session/session_state.dart';
|
||||
|
||||
class Routes {
|
||||
const Routes._();
|
||||
static const splash = '/';
|
||||
@@ -22,6 +40,10 @@ class Routes {
|
||||
static const home = '/home';
|
||||
static const rating = '/rating';
|
||||
static const wallet = '/wallet';
|
||||
static const history = '/history';
|
||||
static const profileEdit = '/account';
|
||||
static const settings = '/settings';
|
||||
static const support = '/support';
|
||||
}
|
||||
|
||||
/// التوجيه يُشتقّ من `SessionCubit` وحده — لا `Navigator.push` بعد الدخول
|
||||
@@ -64,7 +86,7 @@ final appRouter = GoRouter(
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.profile,
|
||||
builder: (context, state) => const ProfilePage(),
|
||||
builder: (context, state) => const ProfileSetupPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.rating,
|
||||
@@ -83,6 +105,22 @@ final appRouter = GoRouter(
|
||||
path: Routes.wallet,
|
||||
builder: (context, state) => const EarningsPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.history,
|
||||
builder: (context, state) => const HistoryPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.profileEdit,
|
||||
builder: (context, state) => const ProfileEditPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.settings,
|
||||
builder: (context, state) => const SettingsPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.support,
|
||||
builder: (context, state) => const SupportPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.home,
|
||||
builder: (context, state) => const DutyPage(),
|
||||
|
||||
@@ -5,16 +5,24 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../api/api_exception.dart';
|
||||
|
||||
import 'app_user.dart';
|
||||
|
||||
import 'session_source.dart';
|
||||
|
||||
import 'session_state.dart';
|
||||
|
||||
/// حالة الجلسة على مستوى التطبيق — مصدر قرار التوجيه الوحيد
|
||||
/// (`core/router.dart` يستمع إليها).
|
||||
class SessionCubit extends Cubit<SessionState> {
|
||||
SessionCubit(this._repo) : super(const SessionState());
|
||||
SessionCubit(this._repo, {Future<void> Function()? onAuthenticated})
|
||||
: _onAuthenticated = onAuthenticated,
|
||||
super(const SessionState());
|
||||
|
||||
final SessionSource _repo;
|
||||
|
||||
/// خطّاف يُنفَّذ مرة عند إثبات الجلسة — يبقي `core/session` جاهلاً بمن
|
||||
/// يستمع إليه.
|
||||
final Future<void> Function()? _onAuthenticated;
|
||||
|
||||
/// تُستدعى مرة عند الإقلاع من شاشة الـsplash.
|
||||
Future<void> restore() async {
|
||||
if (!_repo.hasSession) {
|
||||
@@ -60,8 +68,12 @@ class SessionCubit extends Cubit<SessionState> {
|
||||
user: user,
|
||||
pendingRating: state.pendingRating,
|
||||
));
|
||||
// التقييم المعلّق يُفحص بعد إثبات الجلسة لا قبلها.
|
||||
if (!user.needsProfile) unawaited(_checkPendingRating());
|
||||
// بعد إثبات الجلسة: التقييم المعلّق، وتسجيل رمز الإشعارات (يربط الجهاز
|
||||
// بالمستخدم، فلا معنى له قبل الدخول).
|
||||
if (!user.needsProfile) {
|
||||
unawaited(_checkPendingRating());
|
||||
unawaited(_onAuthenticated?.call() ?? Future<void>.value());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkPendingRating() async {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'tenant_cubit.dart';
|
||||
|
||||
extension FeatureGateX on BuildContext {
|
||||
/// هل الميزة مفعّلة **لهذا المستأجر** وقت التشغيل؟
|
||||
///
|
||||
/// تُقرأ مع علم `Features` الثابت: الأول يقرّر ما بُني، وهذا ما يُعرض.
|
||||
/// أيّهما `false` يُخفي الميزة.
|
||||
bool tenantHas(String feature) =>
|
||||
watch<TenantCubit>().state.has(feature);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// إعداد المستأجر من `GET /tenant/config/:slug` (شكل مُتحقَّق حيّاً،
|
||||
/// docs/38 §10) — بلا توكن، فيُجلب قبل الدخول.
|
||||
///
|
||||
/// **طبقتا الميزات**، ولكلٍّ دورها:
|
||||
/// - `Features` (`const` في `build_config.dart`) يقرّر ما **يُبنى** في
|
||||
/// الـbinary — إطفاؤه يحذف الكود فلا يُستخرج (docs/23 §5).
|
||||
/// - هذا الإعداد يقرّر ما **يُعرض** ممّا بُني، حسب ما اشتراه المستأجر فعلاً.
|
||||
/// الشاشة تتحقّق من الاثنتين: `Features.wallet && tenant.has('wallet')`.
|
||||
class TenantConfig extends Equatable {
|
||||
const TenantConfig({
|
||||
required this.slug,
|
||||
required this.name,
|
||||
required this.countryPack,
|
||||
required this.plan,
|
||||
required this.features,
|
||||
});
|
||||
|
||||
final String slug;
|
||||
final String name;
|
||||
|
||||
/// يحدّد مزوّد الرسائل والعملة وصيغة الهاتف — `jo`/`eg`/`sy`.
|
||||
final String countryPack;
|
||||
|
||||
final String plan;
|
||||
final Map<String, bool> features;
|
||||
|
||||
static const empty = TenantConfig(
|
||||
slug: '',
|
||||
name: '',
|
||||
countryPack: '',
|
||||
plan: '',
|
||||
features: {},
|
||||
);
|
||||
|
||||
/// الافتراض `false` عند غياب المفتاح: ميزة غير معلنة = غير مشتراة.
|
||||
bool has(String feature) => features[feature] ?? false;
|
||||
|
||||
factory TenantConfig.fromJson(Map<String, dynamic> json) {
|
||||
final raw = json['features'];
|
||||
return TenantConfig(
|
||||
slug: json['slug'] as String? ?? '',
|
||||
name: json['name'] as String? ?? '',
|
||||
countryPack: json['countryPack'] as String? ?? '',
|
||||
plan: json['plan'] as String? ?? '',
|
||||
features: raw is Map
|
||||
? {
|
||||
for (final e in raw.entries)
|
||||
e.key.toString(): e.value == true,
|
||||
}
|
||||
: const {},
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'slug': slug,
|
||||
'name': name,
|
||||
'countryPack': countryPack,
|
||||
'plan': plan,
|
||||
'features': features,
|
||||
};
|
||||
|
||||
String encode() => json.encode(toJson());
|
||||
|
||||
static TenantConfig? decode(String? raw) {
|
||||
if (raw == null || raw.isEmpty) return null;
|
||||
try {
|
||||
return TenantConfig.fromJson(json.decode(raw) as Map<String, dynamic>);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [slug, name, countryPack, plan, features];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../api/api_client.dart';
|
||||
|
||||
import '../api/api_exception.dart';
|
||||
|
||||
import '../build_config.dart';
|
||||
|
||||
import 'tenant_config.dart';
|
||||
|
||||
/// يجلب إعداد المستأجر مرة عند الإقلاع، ويخزّنه محلياً.
|
||||
///
|
||||
/// **النسخة المخزّنة تُعرض فوراً** ثم تُحدَّث من الشبكة: إقلاعٌ بلا إنترنت
|
||||
/// يجب أن يعرض التطبيق بميزاته المعروفة آخر مرة، لا شاشة فارغة.
|
||||
class TenantCubit extends Cubit<TenantConfig> {
|
||||
TenantCubit(this._api, this._prefs)
|
||||
: super(TenantConfig.decode(_prefs.getString(_key)) ?? TenantConfig.empty);
|
||||
|
||||
final ApiClient _api;
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
static const _key = 'tenant.config';
|
||||
|
||||
Future<void> load() async {
|
||||
try {
|
||||
final res = await _api.get<Map<String, dynamic>>(
|
||||
'/tenant/config/${BuildConfig.tenantSlug}',
|
||||
);
|
||||
final config = TenantConfig.fromJson(res);
|
||||
emit(config);
|
||||
await _prefs.setString(_key, config.encode());
|
||||
} on ApiException {
|
||||
// الفشل يُبقي النسخة المخزّنة — لا يُطفئ ميزات المستخدم لأن الشبكة
|
||||
// تعثّرت لحظة الإقلاع.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../build_config.dart';
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
import '../router.dart';
|
||||
|
||||
import '../session/session_cubit.dart';
|
||||
|
||||
import '../session/session_state.dart';
|
||||
|
||||
import '../tenant/feature_gate.dart';
|
||||
|
||||
/// الدراور — نقطة تطبيق **طبقتَي الميزات** معاً (docs/23 §5 + docs/38 §10):
|
||||
///
|
||||
/// * `Features.x` ثابت: يقرّر ما بُني في الـbinary. إطفاؤه يحذف الكود.
|
||||
/// * `context.tenantHas('x')`: يقرّر ما يُعرض ممّا بُني، حسب اشتراك المستأجر.
|
||||
///
|
||||
/// أيّهما `false` يُخفي المدخل — ولا يُكتب `if` ثانٍ في أي شاشة.
|
||||
class AppDrawer extends StatelessWidget {
|
||||
const AppDrawer({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final isDriver = AppConfig.appRole == 'driver';
|
||||
|
||||
return Drawer(
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
const _Header(),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: Space.xs),
|
||||
children: [
|
||||
_Item(
|
||||
icon: Icons.person_outline_rounded,
|
||||
label: l10n.menuProfile,
|
||||
route: Routes.profileEdit,
|
||||
),
|
||||
_Item(
|
||||
icon: Icons.route_outlined,
|
||||
label: l10n.menuTrips,
|
||||
route: Routes.history,
|
||||
),
|
||||
if (Features.wallet && context.tenantHas('wallet'))
|
||||
_Item(
|
||||
icon: Icons.account_balance_wallet_outlined,
|
||||
label: isDriver ? l10n.menuEarnings : l10n.menuWallet,
|
||||
route: Routes.wallet,
|
||||
),
|
||||
_Item(
|
||||
icon: Icons.settings_outlined,
|
||||
label: l10n.menuSettings,
|
||||
route: Routes.settings,
|
||||
),
|
||||
_Item(
|
||||
icon: Icons.help_outline_rounded,
|
||||
label: l10n.menuSupport,
|
||||
route: Routes.support,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
Icons.logout_rounded,
|
||||
color: context.tripzColors.danger,
|
||||
),
|
||||
title: Text(
|
||||
l10n.menuLogout,
|
||||
style: TextStyle(color: context.tripzColors.danger),
|
||||
),
|
||||
onTap: () => _confirmLogout(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _confirmLogout(BuildContext context) async {
|
||||
final l10n = context.l10n;
|
||||
final session = context.read<SessionCubit>();
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Text(l10n.menuLogoutConfirm),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text(l10n.actionCancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text(l10n.menuLogout),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// الخروج يمرّ بالجلسة وحدها؛ الراوتر يعيد التوجيه من تلقائه.
|
||||
if (ok == true) await session.logout();
|
||||
}
|
||||
}
|
||||
|
||||
class _Header extends StatelessWidget {
|
||||
const _Header();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SessionCubit, SessionState>(
|
||||
builder: (context, session) {
|
||||
final user = session.user;
|
||||
return Padding(
|
||||
padding: Space.page,
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 26,
|
||||
backgroundColor: context.colors.primaryContainer,
|
||||
child: Icon(
|
||||
Icons.person_rounded,
|
||||
color: context.colors.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: Space.sm),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
user?.name ?? BuildConfig.appName,
|
||||
style: context.texts.titleMedium,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
user?.phone ?? '',
|
||||
textDirection: TextDirection.ltr,
|
||||
style: context.texts.bodySmall?.copyWith(
|
||||
color: context.colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Item extends StatelessWidget {
|
||||
const _Item({required this.icon, required this.label, required this.route});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String route;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon),
|
||||
title: Text(label),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
context.push(route);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
import 'tripz_button.dart';
|
||||
|
||||
/// حالة الفراغ: رسالة **تدلّ على الفعل التالي** لا مجرّد «لا يوجد»
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
import 'tripz_button.dart';
|
||||
|
||||
/// حالة الخطأ: رسالة **بالعربية** مع «أعد المحاولة» — لا شاشة صامتة
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../features/auth/cubit/phone_error.dart';
|
||||
|
||||
import '../api/api_failure.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
/// النقطة **الوحيدة** التي تُترجَم فيها رموز الفشل إلى نصّ.
|
||||
/// الشاشات لا تكتب رسائل خطأ، والـCubit لا يعرف اللغة (راجع `auth_failure.dart`).
|
||||
class AuthFailureText extends StatelessWidget {
|
||||
const AuthFailureText({super.key, required this.failure});
|
||||
|
||||
final AuthFailure failure;
|
||||
|
||||
static String messageOf(BuildContext context, AuthFailure failure) {
|
||||
final l10n = context.l10n;
|
||||
return switch (failure) {
|
||||
AuthFailure.invalidCode => l10n.otpErrInvalid,
|
||||
AuthFailure.tooManyAttempts => l10n.otpErrTooManyAttempts,
|
||||
AuthFailure.rateLimited => l10n.otpErrRateLimited,
|
||||
AuthFailure.network => l10n.errorNetwork,
|
||||
AuthFailure.timeout => l10n.errorTimeout,
|
||||
AuthFailure.server => l10n.errorGeneric,
|
||||
};
|
||||
}
|
||||
|
||||
static String phoneMessageOf(BuildContext context, PhoneError error) {
|
||||
final l10n = context.l10n;
|
||||
return switch (error) {
|
||||
PhoneError.empty => l10n.phoneErrEmpty,
|
||||
PhoneError.leadingZero => l10n.phoneErrLeadingZero,
|
||||
PhoneError.tooShort => l10n.phoneErrShort,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: Space.sm),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline_rounded,
|
||||
size: Sizes.iconSm,
|
||||
color: context.tripzColors.danger,
|
||||
),
|
||||
const SizedBox(width: Space.xs),
|
||||
Expanded(
|
||||
child: Text(
|
||||
messageOf(context, failure),
|
||||
style: context.texts.bodySmall?.copyWith(
|
||||
color: context.tripzColors.danger,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
/// ترويسة موحّدة لشاشات الدخول: أيقونة ثم عنوان ثم سطر شارح.
|
||||
/// «الشاشة مهمة واحدة» — سؤال واحد وزر أساسي واحد أسفلها (docs/26 §8.1).
|
||||
class FormHeader extends StatelessWidget {
|
||||
const FormHeader({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.lead,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String lead;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(Space.sm),
|
||||
decoration: BoxDecoration(
|
||||
color: context.colors.primaryContainer,
|
||||
borderRadius: Radii.card_,
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: Sizes.icon,
|
||||
color: context.colors.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: Space.md),
|
||||
Text(title, style: context.texts.headlineSmall),
|
||||
const SizedBox(height: Space.xs),
|
||||
Text(
|
||||
lead,
|
||||
style: context.texts.bodyMedium?.copyWith(
|
||||
color: context.colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
/// هيكل تحميل — **لا spinner فارغ** (docs/26 §8.4).
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/tripz_colors.dart';
|
||||
|
||||
enum BannerTone { info, success, warning, danger }
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/typography.dart';
|
||||
|
||||
/// حقل رمز التحقّق — أربع خانات (طول رمز تريبز، docs/38 §2).
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import 'empty_view.dart';
|
||||
|
||||
import 'error_view.dart';
|
||||
|
||||
import 'skeleton.dart';
|
||||
|
||||
import 'view_status.dart';
|
||||
|
||||
/// نقطة التنظيم المركزية (docs/26 §6). **ممنوع `Scaffold` خام في
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../design/tokens.dart';
|
||||
|
||||
import '../design/typography.dart';
|
||||
|
||||
/// حقل الإدخال الموحّد (docs/26 §7): نصّ · هاتف · بحث.
|
||||
|
||||
Reference in New Issue
Block a user