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,38 +0,0 @@
|
||||
import '../../../core/api/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;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../core/api/api_exception.dart';
|
||||
|
||||
import '../../../core/api/api_failure.dart';
|
||||
|
||||
import '../../../core/config.dart';
|
||||
|
||||
import '../data/auth_repository.dart';
|
||||
import 'auth_failure.dart';
|
||||
|
||||
import 'login_state.dart';
|
||||
|
||||
import 'phone_error.dart';
|
||||
|
||||
/// تدفّق الدخول كاملاً: الشروط ← إذن الموقع ← الهاتف ← الرمز.
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
import '../../../core/api/api_failure.dart';
|
||||
|
||||
import '../../../core/session/app_user.dart';
|
||||
import 'auth_failure.dart';
|
||||
|
||||
import 'phone_error.dart';
|
||||
|
||||
/// خطوات الدخول بالترتيب الميداني المثبت في سيرو (docs/39 §2): بوابتان
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../core/api/api_exception.dart';
|
||||
import '../../../core/ui/view_status.dart';
|
||||
import '../data/auth_repository.dart';
|
||||
import '../../../core/session/app_user.dart';
|
||||
import 'auth_failure.dart';
|
||||
|
||||
class ProfileState {
|
||||
const ProfileState({
|
||||
this.status = ViewStatus.success,
|
||||
this.saving = false,
|
||||
this.failure,
|
||||
this.user,
|
||||
});
|
||||
|
||||
final ViewStatus status;
|
||||
final bool saving;
|
||||
final AuthFailure? failure;
|
||||
final AppUser? user;
|
||||
|
||||
ProfileState copyWith({
|
||||
ViewStatus? status,
|
||||
bool? saving,
|
||||
AuthFailure? failure,
|
||||
AppUser? user,
|
||||
bool clearFailure = false,
|
||||
}) {
|
||||
return ProfileState(
|
||||
status: status ?? this.status,
|
||||
saving: saving ?? this.saving,
|
||||
failure: clearFailure ? null : (failure ?? this.failure),
|
||||
user: user ?? this.user,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// إكمال الملف بعد أول دخول. عقد الخادم يقبل `{ name, language }` فقط
|
||||
/// (docs/38 §3) — لا اسم أول/أخير ولا بريد كما في سيرو (docs/39 §2).
|
||||
class ProfileCubit extends Cubit<ProfileState> {
|
||||
ProfileCubit(this._repo) : super(const ProfileState());
|
||||
|
||||
final AuthRepository _repo;
|
||||
|
||||
Future<AppUser?> save(String name) async {
|
||||
emit(state.copyWith(saving: true, clearFailure: true));
|
||||
try {
|
||||
final user = await _repo.updateProfile(name: name.trim());
|
||||
emit(state.copyWith(saving: false, user: user));
|
||||
return user;
|
||||
} on ApiException catch (e) {
|
||||
emit(state.copyWith(saving: false, failure: e.toAuthFailure()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user