Настройки, авторизация
This commit is contained in:
@@ -3,6 +3,12 @@ import 'package:dio/dio.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/network/api_client.dart';
|
||||
import '../../features/auth/data/datasources/auth_local_datasource.dart';
|
||||
import '../../features/auth/data/datasources/auth_local_datasource_impl.dart';
|
||||
import '../../features/auth/data/datasources/auth_remote_datasource.dart';
|
||||
import '../../features/auth/data/datasources/auth_remote_datasource_impl.dart';
|
||||
import '../../features/auth/data/repositories/auth_repository_impl.dart';
|
||||
import '../../features/auth/domain/repositories/auth_repository.dart';
|
||||
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import '../../features/chat/presentation/bloc/chat_bloc.dart';
|
||||
import '../../features/settings/data/datasources/settings_local_datasource.dart';
|
||||
@@ -25,7 +31,15 @@ Future<void> initDependencies() async {
|
||||
|
||||
// Core - Dio (with dynamic base URL from settings)
|
||||
sl.registerLazySingleton<Dio>(() {
|
||||
final apiUrl = prefs.getString('api_url') ?? 'https://api.messenger.app';
|
||||
final prefs = sl<SharedPreferences>();
|
||||
var apiUrl = prefs.getString('api_url') ?? 'https://api.messenger.app';
|
||||
|
||||
// Нормализуем URL: убираем /api в конце если есть
|
||||
apiUrl = apiUrl.replaceAll(RegExp(r'/+$'), '');
|
||||
if (apiUrl.endsWith('/api')) {
|
||||
apiUrl = apiUrl.substring(0, apiUrl.length - 4).replaceAll(RegExp(r'/+$'), '');
|
||||
}
|
||||
|
||||
return Dio(BaseOptions(
|
||||
baseUrl: apiUrl,
|
||||
connectTimeout: const Duration(seconds: 30),
|
||||
@@ -46,7 +60,19 @@ Future<void> initDependencies() async {
|
||||
sl.registerFactory<SettingsBloc>(() => SettingsBloc(sl()));
|
||||
|
||||
// Auth
|
||||
sl.registerFactory<AuthBloc>(() => AuthBloc());
|
||||
sl.registerLazySingleton<AuthLocalDataSource>(
|
||||
() => AuthLocalDataSourceImpl(sl()),
|
||||
);
|
||||
sl.registerLazySingleton<AuthRemoteDataSource>(
|
||||
() => AuthRemoteDataSourceImpl(sl()),
|
||||
);
|
||||
sl.registerLazySingleton<AuthRepository>(
|
||||
() => AuthRepositoryImpl(
|
||||
remoteDataSource: sl(),
|
||||
localDataSource: sl(),
|
||||
),
|
||||
);
|
||||
sl.registerFactory<AuthBloc>(() => AuthBloc(authRepository: sl()));
|
||||
|
||||
// Chat
|
||||
sl.registerFactory<ChatBloc>(() => ChatBloc());
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import '../../features/auth/presentation/bloc/auth_state.dart';
|
||||
import '../../features/auth/presentation/pages/login_page.dart';
|
||||
import '../../features/settings/presentation/pages/settings_page.dart';
|
||||
import '../router/chats_placeholder.dart';
|
||||
|
||||
@@ -89,16 +85,6 @@ class SettingsTab extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, authState) {
|
||||
return authState.when(
|
||||
initial: () => const Center(child: CircularProgressIndicator()),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
authenticated: (_) => const SettingsPage(),
|
||||
unauthenticated: () => const LoginPage(),
|
||||
error: (_) => const LoginPage(),
|
||||
);
|
||||
},
|
||||
);
|
||||
return const SettingsPage();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user