diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 42ec3497..3275dbdb 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -67,7 +67,7 @@
UIViewControllerBasedStatusBarAppearance
- LSApplicationQueriesSchemes
+ LSApplicationQueriesSchemes
yandexauth
yandexauth2
diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements
index 7b8ca2a8..4ed4ad00 100644
--- a/ios/Runner/Runner.entitlements
+++ b/ios/Runner/Runner.entitlements
@@ -8,6 +8,7 @@
applinks:eatvio.ru
applinks:www.eatvio.ru
+ applinks:5399b03636104c6d920b87c1ad329254.oauth.yandex.ru
diff --git a/lib/core/app_config.dart b/lib/core/app_config.dart
index 554a326f..3fb06b39 100644
--- a/lib/core/app_config.dart
+++ b/lib/core/app_config.dart
@@ -1,3 +1,4 @@
+import 'package:eatvio_app/core/internet_connection_cubit/internet_connection_cubit.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/views/cubit/views_cubit.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/new_messages_cubit/new_messages_cubit.dart';
@@ -5,7 +6,6 @@ import 'package:eatvio_app/features/notifications/presentation/notifications_cub
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart';
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
-import 'package:eatvio_app/features/internet_connection_checker/internet_connection_checker_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -16,18 +16,12 @@ class AppConfig {
/// Список глобальных BlocProvider'ов
static List get globalBlocProviders => [
BlocProvider(create: (context) => sl()),
- BlocProvider(
- create: (context) => sl()..getNotifications(),
- ),
- BlocProvider(
- create: (context) => sl()..loadFeedBlogPostList(),
- ),
- BlocProvider(
- create: (context) => sl()..getMyProfile(),
- ),
- BlocProvider(
- create: (context) => sl()..getChatRoomsWithLoading(),
- ),
+ BlocProvider(create: (context) => sl()..getNotifications()),
+ BlocProvider(create: (context) => sl()..loadFeedBlogPostList()),
+ BlocProvider(create: (context) => sl()..getMyProfile()),
+ BlocProvider(create: (context) => sl()..getChatRoomsWithLoading()),
+ BlocProvider(create: (context) => sl()),
+ BlocProvider(lazy: false, create: (context) => sl()),
];
/// Делегаты локализации
@@ -39,15 +33,5 @@ class AppConfig {
];
/// Поддерживаемые локали
- static const List supportedLocales = [
- Locale.fromSubtags(languageCode: 'ru'),
- ];
-
- /// Создание обертки для проверки интернет-соединения
- static Widget createInternetConnectionWrapper(Widget child) {
- return BlocProvider(
- create: (context) => sl(),
- child: InternetConnectionCheckerScreen(child: child),
- );
- }
+ static const List supportedLocales = [Locale.fromSubtags(languageCode: 'ru')];
}
diff --git a/lib/core/const.dart b/lib/core/const.dart
index 98f7bc4a..a5f06149 100644
--- a/lib/core/const.dart
+++ b/lib/core/const.dart
@@ -1,6 +1,6 @@
import 'package:eatvio_app/core/env_config.dart';
-String baseUrl = EnvConfig.baseUrl;
+String baseUrl = EnvConfig.devBaseUrl;
bool hidePlans = const bool.fromEnvironment('HIDE_PLANS', defaultValue: false);
const buildDate = String.fromEnvironment('BUILD_DATE', defaultValue: '');
diff --git a/lib/core/di/cubit_registrations.dart b/lib/core/di/cubit_registrations.dart
index ec2de9ce..d2324a9b 100644
--- a/lib/core/di/cubit_registrations.dart
+++ b/lib/core/di/cubit_registrations.dart
@@ -1,3 +1,4 @@
+import 'package:eatvio_app/core/internet_connection_cubit/internet_connection_cubit.dart';
import 'package:eatvio_app/core/views/cubit/views_cubit.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit/auth_cubit.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/reset_password_cubit/reset_password_cubit.dart';
@@ -64,6 +65,7 @@ class CubitRegistrations {
sl.registerLazySingleton(() => NotificationsCubit(wsManager: sl(), notificationsRepository: sl()));
sl.registerLazySingleton(() => ProfileAvatarCubit(profileRepository: sl()));
sl.registerLazySingleton(() => ChatsCubit(chatRepository: sl(), wsManager: sl(), profileRepository: sl()));
+ sl.registerLazySingleton(() => InternetConnectionCubit());
}
/// Регистрация Cubit'ов как фабрик
diff --git a/lib/core/internet_connection_cubit/internet_connection_cubit.dart b/lib/core/internet_connection_cubit/internet_connection_cubit.dart
new file mode 100644
index 00000000..67427c6c
--- /dev/null
+++ b/lib/core/internet_connection_cubit/internet_connection_cubit.dart
@@ -0,0 +1,73 @@
+import 'dart:async';
+import 'dart:developer';
+
+import 'package:connectivity_plus/connectivity_plus.dart';
+import 'package:eatvio_app/core/env_config.dart';
+import 'package:eatvio_app/core/internet_connection_cubit/internet_connection_state.dart';
+import 'package:eatvio_app/core/utils/toasts.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:http/http.dart' as http;
+
+class InternetConnectionCubit extends Cubit {
+ InternetConnectionCubit() : super(InternetConnectionState()) {
+ checkConnection();
+ _connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateAccessStatus);
+ _listener = AppLifecycleListener(
+ onResume: () async {
+ _connectivitySubscription.resume();
+ await checkConnection();
+ },
+ onHide: _connectivitySubscription.pause,
+ onPause: _connectivitySubscription.pause,
+ );
+ }
+
+ final Connectivity _connectivity = Connectivity();
+ late StreamSubscription> _connectivitySubscription;
+ late final AppLifecycleListener _listener;
+
+ Future checkConnection() async {
+ late List result;
+
+ try {
+ result = await _connectivity.checkConnectivity();
+ } on PlatformException catch (e) {
+ log('Couldn\'t check connectivity status', error: e);
+ return;
+ }
+
+ return _updateAccessStatus(result);
+ }
+
+ Future _updateAccessStatus(List result) async {
+ final hasInternet = await _checkInternetAccess(result);
+ if (!hasInternet) showInternetConnectionToast();
+ emit(state.copyWith(isInternetAvailable: hasInternet));
+ }
+
+ Future _checkInternetAccess(List result) async {
+ if (result.contains(ConnectivityResult.none)) {
+ return false;
+ }
+
+ final uris = [Uri.parse(EnvConfig.googleCheckUrl), Uri.parse(EnvConfig.yandexCheckUrl), Uri.parse(EnvConfig.devBaseUrl), Uri.parse(EnvConfig.baseUrl)];
+ for (final uri in uris) {
+ try {
+ final response = await http.get(uri).timeout(const Duration(seconds: 3));
+ return response.statusCode >= 100 && response.statusCode < 600;
+ } catch (e) {
+ continue;
+ }
+ }
+ return false;
+ }
+
+ @override
+ Future close() {
+ _connectivitySubscription.cancel();
+ _listener.dispose();
+ return super.close();
+ }
+}
diff --git a/lib/core/internet_connection_cubit/internet_connection_state.dart b/lib/core/internet_connection_cubit/internet_connection_state.dart
new file mode 100644
index 00000000..95c831e1
--- /dev/null
+++ b/lib/core/internet_connection_cubit/internet_connection_state.dart
@@ -0,0 +1,13 @@
+import 'package:freezed_annotation/freezed_annotation.dart';
+
+part 'internet_connection_state.freezed.dart';
+
+
+@freezed
+abstract class InternetConnectionState with _$InternetConnectionState {
+
+ factory InternetConnectionState({
+ @Default(true) bool isInternetAvailable,
+ }) = _InternetConnectionState;
+
+}
\ No newline at end of file
diff --git a/lib/core/utils/toasts.dart b/lib/core/utils/toasts.dart
index 3d4fda0d..4683cb86 100644
--- a/lib/core/utils/toasts.dart
+++ b/lib/core/utils/toasts.dart
@@ -38,4 +38,16 @@ void showSuccessToast(String message) {
textColor: appTheme.whiteA700,
fontSize: 16.0,
);
-}
\ No newline at end of file
+}
+
+void showInternetConnectionToast() {
+ Fluttertoast.showToast(
+ msg: 'Проверьте подключение к интернету',
+ toastLength: Toast.LENGTH_LONG,
+ gravity: ToastGravity.TOP,
+ timeInSecForIosWeb: 3,
+ backgroundColor: appTheme.red,
+ textColor: Colors.white,
+ fontSize: 16.0,
+ );
+}
diff --git a/lib/main.dart b/lib/main.dart
index c6501d49..fa5ff699 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -23,8 +23,7 @@ class MyApp extends StatelessWidget {
child: KeyboardDismisser(
child: MaterialApp.router(
theme: ThemeHelper().themeData(),
- routerConfig: AppRouter.appRouter,
- builder: (context, child) => AppConfig.createInternetConnectionWrapper(child!),
+ routerConfig: AppRouter.appRouter,
debugShowCheckedModeBanner: false,
localizationsDelegates: AppConfig.localizationDelegates,
supportedLocales: AppConfig.supportedLocales,