flutter(rider): rebuild lib on Cubit/Bloc + Tripz backend (core + auth slice)
- 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>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../data/auth_repository.dart';
|
||||
import 'auth_state.dart';
|
||||
|
||||
class AuthCubit extends Cubit<AuthState> {
|
||||
final AuthRepository _repo;
|
||||
|
||||
AuthCubit(this._repo) : super(const AuthState());
|
||||
|
||||
Future<void> checkAuth() async {
|
||||
final user = await _repo.me();
|
||||
emit(state.copyWith(
|
||||
status: user != null ? AuthStatus.authenticated : AuthStatus.unauthenticated,
|
||||
user: user,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> sendOtp(String phone) async {
|
||||
if (phone.trim().isEmpty) {
|
||||
emit(state.copyWith(status: AuthStatus.error, error: 'أدخل رقم الهاتف'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
emit(state.copyWith(status: AuthStatus.authenticating, phone: phone.trim()));
|
||||
await _repo.sendOtp(phone.trim());
|
||||
emit(state.copyWith(status: AuthStatus.codeSent, phone: phone.trim()));
|
||||
} catch (_) {
|
||||
emit(state.copyWith(status: AuthStatus.error, error: 'تعذّر إرسال الرمز'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> verify(String code) async {
|
||||
try {
|
||||
emit(state.copyWith(status: AuthStatus.authenticating));
|
||||
final user = await _repo.verify(state.phone, code.trim());
|
||||
emit(state.copyWith(status: AuthStatus.authenticated, user: user));
|
||||
} catch (_) {
|
||||
emit(state.copyWith(status: AuthStatus.error, error: 'رمز غير صحيح'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await _repo.logout();
|
||||
emit(const AuthState(status: AuthStatus.unauthenticated));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../data/auth_repository.dart';
|
||||
|
||||
enum AuthStatus {
|
||||
unknown,
|
||||
unauthenticated,
|
||||
codeSent,
|
||||
authenticating,
|
||||
authenticated,
|
||||
error,
|
||||
}
|
||||
|
||||
class AuthState extends Equatable {
|
||||
final AuthStatus status;
|
||||
final String phone;
|
||||
final AppUser? user;
|
||||
final String? error;
|
||||
|
||||
const AuthState({
|
||||
this.status = AuthStatus.unknown,
|
||||
this.phone = '',
|
||||
this.user,
|
||||
this.error,
|
||||
});
|
||||
|
||||
AuthState copyWith({
|
||||
AuthStatus? status,
|
||||
String? phone,
|
||||
AppUser? user,
|
||||
String? error,
|
||||
}) {
|
||||
return AuthState(
|
||||
status: status ?? this.status,
|
||||
phone: phone ?? this.phone,
|
||||
user: user ?? this.user,
|
||||
error: error,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, phone, user, error];
|
||||
}
|
||||
Reference in New Issue
Block a user