Приложение на флаторе, настройки
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/network/api_client.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';
|
||||
import '../../features/settings/data/datasources/settings_remote_datasource.dart';
|
||||
import '../../features/settings/data/repositories/settings_repository_impl.dart';
|
||||
import '../../features/settings/domain/repositories/settings_repository.dart';
|
||||
import '../../features/settings/presentation/bloc/settings_bloc.dart';
|
||||
|
||||
final sl = GetIt.instance;
|
||||
|
||||
Future<void> initDependencies() async {
|
||||
// Core - SharedPreferences
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
sl.registerLazySingleton<SharedPreferences>(() => prefs);
|
||||
|
||||
// Core - Settings Local DataSource
|
||||
sl.registerLazySingleton<SettingsLocalDataSource>(
|
||||
() => SettingsLocalDataSourceImpl(sl()),
|
||||
);
|
||||
|
||||
// Core - Dio (with dynamic base URL from settings)
|
||||
sl.registerLazySingleton<Dio>(() {
|
||||
final apiUrl = prefs.getString('api_url') ?? 'https://api.messenger.app';
|
||||
return Dio(BaseOptions(
|
||||
baseUrl: apiUrl,
|
||||
connectTimeout: const Duration(seconds: 30),
|
||||
receiveTimeout: const Duration(seconds: 30),
|
||||
));
|
||||
});
|
||||
|
||||
// Core - API Client
|
||||
sl.registerLazySingleton<ApiClient>(() => ApiClient(sl()));
|
||||
|
||||
// Settings
|
||||
sl.registerLazySingleton<SettingsRemoteDataSource>(
|
||||
() => SettingsRemoteDataSourceImpl(sl()),
|
||||
);
|
||||
sl.registerLazySingleton<SettingsRepository>(
|
||||
() => SettingsRepositoryImpl(sl(), sl()),
|
||||
);
|
||||
sl.registerFactory<SettingsBloc>(() => SettingsBloc(sl()));
|
||||
|
||||
// Auth
|
||||
sl.registerFactory<AuthBloc>(() => AuthBloc());
|
||||
|
||||
// Chat
|
||||
sl.registerFactory<ChatBloc>(() => ChatBloc());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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';
|
||||
|
||||
class MainScreen extends StatefulWidget {
|
||||
static const String routeName = '/main';
|
||||
|
||||
const MainScreen({super.key});
|
||||
|
||||
@override
|
||||
State<MainScreen> createState() => _MainScreenState();
|
||||
}
|
||||
|
||||
class _MainScreenState extends State<MainScreen> {
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: IndexedStack(
|
||||
index: _currentIndex,
|
||||
children: const [
|
||||
ChatsTab(),
|
||||
ContactsTab(),
|
||||
SettingsTab(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: _currentIndex,
|
||||
onTap: (index) => setState(() => _currentIndex = index),
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.chat_bubble_outline),
|
||||
activeIcon: Icon(Icons.chat_bubble),
|
||||
label: 'Чаты',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.contacts_outlined),
|
||||
activeIcon: Icon(Icons.contacts),
|
||||
label: 'Контакты',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
activeIcon: Icon(Icons.settings),
|
||||
label: 'Настройки',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatsTab extends StatelessWidget {
|
||||
const ChatsTab({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const ChatsPage();
|
||||
}
|
||||
}
|
||||
|
||||
class ContactsTab extends StatelessWidget {
|
||||
const ContactsTab({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.contacts_outlined, size: 64, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Text('Контакты', style: TextStyle(fontSize: 18)),
|
||||
SizedBox(height: 8),
|
||||
Text('Функция в разработке', style: TextStyle(color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsTab extends StatelessWidget {
|
||||
const SettingsTab({super.key});
|
||||
|
||||
@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(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user