Отображение чатов

This commit is contained in:
Халимов Рустам
2026-05-14 22:56:42 +03:00
parent ccffc5a53c
commit 0b013def2e
29 changed files with 6365 additions and 842 deletions
@@ -10,6 +10,14 @@ 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 '../../core/database/database_service.dart';
import '../../core/network/signalr_service.dart';
import '../../features/chat/data/datasources/chat_local_datasource.dart';
import '../../features/chat/data/datasources/chat_local_datasource_impl.dart';
import '../../features/chat/data/datasources/chat_remote_datasource.dart';
import '../../features/chat/data/datasources/chat_remote_datasource_impl.dart';
import '../../features/chat/data/repositories/chat_repository_impl.dart';
import '../../features/chat/domain/repositories/chat_repository.dart';
import '../../features/chat/presentation/bloc/chat_bloc.dart';
import '../../features/settings/data/datasources/settings_local_datasource.dart';
import '../../features/settings/data/datasources/settings_remote_datasource.dart';
@@ -40,16 +48,34 @@ Future<void> initDependencies() async {
apiUrl = apiUrl.substring(0, apiUrl.length - 4).replaceAll(RegExp(r'/+$'), '');
}
return Dio(BaseOptions(
final dio = Dio(BaseOptions(
baseUrl: apiUrl,
connectTimeout: const Duration(seconds: 30),
receiveTimeout: const Duration(seconds: 30),
));
dio.interceptors.add(InterceptorsWrapper(
onRequest: (options, handler) {
final token = prefs.getString('access_token');
if (token != null) {
options.headers['Authorization'] = 'Bearer $token';
}
return handler.next(options);
},
));
return dio;
});
// Core - API Client
sl.registerLazySingleton<ApiClient>(() => ApiClient(sl()));
// Core - Database & SignalR
final dbService = DatabaseService();
await dbService.init();
sl.registerSingleton<DatabaseService>(dbService);
sl.registerLazySingleton<SignalRService>(() => SignalRService(sl()));
// Settings
sl.registerLazySingleton<SettingsRemoteDataSource>(
() => SettingsRemoteDataSourceImpl(sl()),
@@ -75,5 +101,18 @@ Future<void> initDependencies() async {
sl.registerFactory<AuthBloc>(() => AuthBloc(authRepository: sl()));
// Chat
sl.registerFactory<ChatBloc>(() => ChatBloc());
sl.registerLazySingleton<ChatLocalDataSource>(
() => ChatLocalDataSourceImpl(sl<DatabaseService>().isar),
);
sl.registerLazySingleton<ChatRemoteDataSource>(
() => ChatRemoteDataSourceImpl(sl()),
);
sl.registerLazySingleton<ChatRepository>(
() => ChatRepositoryImpl(
remoteDataSource: sl(),
localDataSource: sl(),
signalRService: sl(),
),
);
sl.registerFactory<ChatBloc>(() => ChatBloc(chatRepository: sl()));
}
@@ -1,21 +0,0 @@
import 'package:flutter/material.dart';
class ChatsPage extends StatelessWidget {
const ChatsPage({super.key});
@override
Widget build(BuildContext context) {
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.chat_bubble_outline, size: 64, color: Colors.grey),
SizedBox(height: 16),
Text('Чаты', style: TextStyle(fontSize: 18)),
SizedBox(height: 8),
Text('Функция в разработке', style: TextStyle(color: Colors.grey)),
],
),
);
}
}
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import '../../features/settings/presentation/pages/settings_page.dart';
import '../router/chats_placeholder.dart';
import '../../features/chat/presentation/pages/chats_page.dart';
import '../../l10n/app_localizations.dart';
class MainScreen extends StatefulWidget {
static const String routeName = '/main';
@@ -16,6 +17,7 @@ class _MainScreenState extends State<MainScreen> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return Scaffold(
body: IndexedStack(
index: _currentIndex,
@@ -29,21 +31,21 @@ class _MainScreenState extends State<MainScreen> {
currentIndex: _currentIndex,
onTap: (index) => setState(() => _currentIndex = index),
type: BottomNavigationBarType.fixed,
items: const [
items: [
BottomNavigationBarItem(
icon: Icon(Icons.chat_bubble_outline),
activeIcon: Icon(Icons.chat_bubble),
label: 'Чаты',
icon: const Icon(Icons.chat_bubble_outline),
activeIcon: const Icon(Icons.chat_bubble),
label: l10n.chats,
),
BottomNavigationBarItem(
icon: Icon(Icons.contacts_outlined),
activeIcon: Icon(Icons.contacts),
label: 'Контакты',
icon: const Icon(Icons.contacts_outlined),
activeIcon: const Icon(Icons.contacts),
label: l10n.contacts,
),
BottomNavigationBarItem(
icon: Icon(Icons.settings_outlined),
activeIcon: Icon(Icons.settings),
label: 'Настройки',
icon: const Icon(Icons.settings_outlined),
activeIcon: const Icon(Icons.settings),
label: l10n.settings,
),
],
),