From f1945202fe7b476e21932deef5114b377c65c798 Mon Sep 17 00:00:00 2001 From: misha Date: Tue, 30 Sep 2025 17:33:30 +0300 Subject: [PATCH 1/4] feat(internetConnection): changed logic for internet connection checking and displaying state --- .../internet_connection_cubit.dart | 73 +++++++++++++++++++ .../internet_connection_state.dart | 13 ++++ lib/core/locator_service.dart | 3 + lib/core/utils/toasts.dart | 14 +++- lib/main.dart | 8 +- 5 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 lib/core/internet_connection_cubit/internet_connection_cubit.dart create mode 100644 lib/core/internet_connection_cubit/internet_connection_state.dart 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..fa9a3527 --- /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); + 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/locator_service.dart b/lib/core/locator_service.dart index 37713f29..ffe747a9 100644 --- a/lib/core/locator_service.dart +++ b/lib/core/locator_service.dart @@ -5,6 +5,7 @@ import 'package:eatvio_app/core/const.dart'; import 'package:eatvio_app/core/dio/phone_verify_error_interceptor.dart'; import 'package:eatvio_app/core/firebase_api.dart'; import 'package:eatvio_app/core/interceptors/token_interceptor.dart'; +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/core/views/repository/views_repository.dart'; import 'package:eatvio_app/core/views/service/views_service.dart'; @@ -45,6 +46,7 @@ import 'package:eatvio_app/features/blog_post_create/services/blog_post_service. import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/new_messages_cubit/new_messages_cubit.dart'; import 'package:eatvio_app/features/finances_and_consultations_archive/cubit/consultant_finances/consultant_finances_cubit.dart'; import 'package:eatvio_app/features/finances_and_consultations_archive/cubit/user_purchases/user_purchases_cubit.dart'; +import 'package:eatvio_app/features/internet_connection_checker/internet_connection_checker_screen.dart'; import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart'; import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_cubit.dart'; import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart'; @@ -128,6 +130,7 @@ Future init() async { 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 factories sl.registerFactory(() => FeedCubit(feedRepository: sl())); 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 d716f3fa..c9e9a3d6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:io' as io; import 'package:eatvio_app/core/app_router.dart'; +import 'package:eatvio_app/core/internet_connection_cubit/internet_connection_cubit.dart'; import 'package:eatvio_app/core/locator_service.dart' as di; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; @@ -9,7 +10,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/firebase_options.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:firebase_core/firebase_core.dart'; @@ -58,20 +58,18 @@ class MyApp extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider(create: (context) => sl()), + 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()), ], child: Portal( child: KeyboardDismisser( child: MaterialApp.router( theme: ThemeHelper().themeData(), routerConfig: AppRouter.appRouter, - builder: (context, child) => BlocProvider( - create: (context) => sl(), - child: InternetConnectionCheckerScreen(child: child!), - ), debugShowCheckedModeBanner: false, localizationsDelegates: const [ S.delegate, From d18ad865909c556a7807053e680a1de484141bff Mon Sep 17 00:00:00 2001 From: misha Date: Wed, 1 Oct 2025 17:24:48 +0300 Subject: [PATCH 2/4] feat(internetConnection): fixed yandex sign in compilation --- ...otlin-compiler-10039299475187077818.salive | 0 ios/Runner/AppDelegate.swift | 19 ++++++++++++++++++- ios/Runner/Info.plist | 19 +++++++++++++++++++ ios/Runner/Runner.entitlements | 1 + lib/core/const.dart | 2 +- .../internet_connection_cubit.dart | 2 +- lib/main.dart | 2 +- 7 files changed, 41 insertions(+), 4 deletions(-) delete mode 100644 android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive diff --git a/android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive b/android/.kotlin/sessions/kotlin-compiler-10039299475187077818.salive deleted file mode 100644 index e69de29b..00000000 diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index b6363034..fc70b0b0 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,5 +1,6 @@ -import UIKit import Flutter +import UIKit +import YandexLoginSDK @main @objc class AppDelegate: FlutterAppDelegate { @@ -10,4 +11,20 @@ import Flutter GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } + + @available(iOS 8.0, *) + func application( + _ application: UIApplication, continue userActivity: NSUserActivity, + restorationHandler: @escaping ([Any]?) -> Void + ) -> Bool { + YXLSdk.shared.processUserActivity(userActivity) + return true + } + + override public func application( + _ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:] + ) -> Bool { + return YXLSdk.shared.handleOpen( + url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String) + } } diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 7e82c5b2..3275dbdb 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -67,5 +67,24 @@ UIViewControllerBasedStatusBarAppearance + LSApplicationQueriesSchemes + + yandexauth + yandexauth2 + yandexauth4 + + YAClientId + 5399b03636104c6d920b87c1ad329254 + CFBundleURLTypes + + + CFBundleURLName + YandexLoginSDK + CFBundleURLSchemes + + yx5399b03636104c6d920b87c1ad329254 + + + 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/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/internet_connection_cubit/internet_connection_cubit.dart b/lib/core/internet_connection_cubit/internet_connection_cubit.dart index fa9a3527..67427c6c 100644 --- a/lib/core/internet_connection_cubit/internet_connection_cubit.dart +++ b/lib/core/internet_connection_cubit/internet_connection_cubit.dart @@ -43,7 +43,7 @@ class InternetConnectionCubit extends Cubit { Future _updateAccessStatus(List result) async { final hasInternet = await _checkInternetAccess(result); - showInternetConnectionToast(); + if (!hasInternet) showInternetConnectionToast(); emit(state.copyWith(isInternetAvailable: hasInternet)); } diff --git a/lib/main.dart b/lib/main.dart index c9e9a3d6..0343afd2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -63,7 +63,7 @@ class MyApp extends StatelessWidget { BlocProvider(create: (context) => sl()..loadFeedBlogPostList()), BlocProvider(create: (context) => sl()..getMyProfile()), BlocProvider(create: (context) => sl()..getChatRoomsWithLoading()), - BlocProvider(create: (context) => sl()), + BlocProvider(create: (context) => sl(), lazy: false), ], child: Portal( child: KeyboardDismisser( From 09d025252d6587bde222d797b158462aa6df7711 Mon Sep 17 00:00:00 2001 From: misha Date: Thu, 2 Oct 2025 10:25:10 +0300 Subject: [PATCH 3/4] feat(fixes): fixed analyzer issue --- lib/core/locator_service.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/core/locator_service.dart b/lib/core/locator_service.dart index ffe747a9..c9c61e56 100644 --- a/lib/core/locator_service.dart +++ b/lib/core/locator_service.dart @@ -46,7 +46,6 @@ import 'package:eatvio_app/features/blog_post_create/services/blog_post_service. import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/new_messages_cubit/new_messages_cubit.dart'; import 'package:eatvio_app/features/finances_and_consultations_archive/cubit/consultant_finances/consultant_finances_cubit.dart'; import 'package:eatvio_app/features/finances_and_consultations_archive/cubit/user_purchases/user_purchases_cubit.dart'; -import 'package:eatvio_app/features/internet_connection_checker/internet_connection_checker_screen.dart'; import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart'; import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_cubit.dart'; import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart'; From 87c0d4ec2ae01b3ecd638c6a3c15d3891cc11c4c Mon Sep 17 00:00:00 2001 From: misha Date: Wed, 8 Oct 2025 14:04:25 +0300 Subject: [PATCH 4/4] feat(analyzer): fixed issues --- lib/core/app_config.dart | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/lib/core/app_config.dart b/lib/core/app_config.dart index 7017e570..3fb06b39 100644 --- a/lib/core/app_config.dart +++ b/lib/core/app_config.dart @@ -6,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'; @@ -17,25 +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(), - ), - BlocProvider( - lazy: false, - 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()), + BlocProvider(lazy: false, create: (context) => sl()), ]; /// Делегаты локализации @@ -47,8 +33,5 @@ class AppConfig { ]; /// Поддерживаемые локали - static const List supportedLocales = [ - Locale.fromSubtags(languageCode: 'ru'), - ]; - + static const List supportedLocales = [Locale.fromSubtags(languageCode: 'ru')]; }