From b64c03a1d7c4aa521d32de98145220b6d7881a1d Mon Sep 17 00:00:00 2001 From: Brambora0 Date: Wed, 5 Oct 2022 20:31:00 +0200 Subject: [PATCH] =?UTF-8?q?fix/zobrazeni=5Fchybove=5Fhlasky=5Fpripojeni=5F?= =?UTF-8?q?k=5Finternetu=20(#373)=20Oprava=20zobrazen=C3=AD=20chybov=C3=A9?= =?UTF-8?q?=20hl=C3=A1=C5=A1ky=20o=20p=C5=99ipojen=C3=AD=20k=20internetu?= =?UTF-8?q?=20Zlep=C5=A1en=C3=AD=20zp=C5=AFsobu=20zabr=C3=A1n=C4=9Bn=C3=AD?= =?UTF-8?q?=20dvojit=C3=A9ho=20stahov=C3=A1n=C3=AD=20prohl=C3=ADdek=20Loka?= =?UTF-8?q?lizov=C3=A1n=C3=AD=20text=C5=AF=20v=20no=5Fconnection=5Fmessage?= =?UTF-8?q?.dart=20(https://github.com/Loono-cz/loono-tasks/issues/92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/l10n/intl_cs.arb | 6 ++- lib/ui/screens/main/main_screen.dart | 51 ++++++++----------- .../main/pre_auth/pre_auth_main_screen.dart | 25 ++++----- lib/ui/widgets/no_connection_message.dart | 7 +-- pubspec.lock | 1 - 5 files changed, 41 insertions(+), 49 deletions(-) diff --git a/lib/l10n/intl_cs.arb b/lib/l10n/intl_cs.arb index 7a1f7ca6..8934ef51 100644 --- a/lib/l10n/intl_cs.arb +++ b/lib/l10n/intl_cs.arb @@ -1433,5 +1433,9 @@ "disposable": "Jednorázové", "@disposable": {}, "regularly": "Pravidelné", - "@regularly": {} + "@regularly": {}, + "no_connection_message": "Žádné připojení", + "@no_connection_message":{}, + "no_connection_message_check_connection": "Prosím zkontroluj své připojení k síti", + "@no_connection_message_check_connection":{} } diff --git a/lib/ui/screens/main/main_screen.dart b/lib/ui/screens/main/main_screen.dart index 972798d6..02485232 100644 --- a/lib/ui/screens/main/main_screen.dart +++ b/lib/ui/screens/main/main_screen.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:another_flushbar/flushbar.dart'; import 'package:auto_route/auto_route.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; @@ -28,47 +29,40 @@ class _MainScreenState extends State { bool connectivityLocked = true; - final analyticsTabNames = ['PreventionTab', 'FindDoctorTab', 'ExploreSectionTab']; + final analyticsTabNames = [ + 'PreventionTab', + 'FindDoctorTab', + 'ExploreSectionTab' + ]; - final noConnectionMessage = noConnectionFlushbar(); + Flushbar? noConnectionMessage; void evalConnectivity(ConnectivityResult result) { if (result == ConnectivityResult.none) { - noConnectionMessage.show(context); - } else { - noConnectionMessage.dismiss(context); + if (noConnectionMessage?.isShowing() == false) { + noConnectionMessage?.show(context); + } + } else if (noConnectionMessage?.isDismissed() == false) { + noConnectionMessage?.dismiss(context); } } @override void initState() { super.initState(); - final examinationsProvider = Provider.of(context, listen: false); + final examinationsProvider = + Provider.of(context, listen: false); - WidgetsBinding.instance.addPostFrameCallback( - (_) => examinationsProvider.fetchExaminations(), - ); checkAndShowDonatePage(context, mounted: mounted); registry.get().sync(); - /// lock connectivity for the first 300ms to prevent multiple api calls on init - Future.delayed(const Duration(milliseconds: 300), () { - setState(() { - connectivityLocked = false; - }); - }); - - Connectivity().checkConnectivity().then( - evalConnectivity, - ); - - subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { + subscription = Connectivity() + .onConnectivityChanged + .listen((ConnectivityResult result) { evalConnectivity(result); - /// fetch examinations after network reconnection - if (result != ConnectivityResult.none && - examinationsProvider.examinations == null && - !connectivityLocked) { + /// re-evaluate connection status after network reconnection + if (result != ConnectivityResult.none && !examinationsProvider.loading) { examinationsProvider.fetchExaminations(); } }); @@ -76,15 +70,14 @@ class _MainScreenState extends State { @override void dispose() { - super.dispose(); subscription?.cancel(); + super.dispose(); } @override Widget build(BuildContext context) { - final hasNotification = - context.select((state) => state.hasNotification); - + noConnectionMessage ??= noConnectionFlushbar(context: context); + final hasNotification = context.select((state) => state.hasNotification); return WillPopScope( /// index 2 has its own WillPopScope for webview navigation. This prevents pop event override onWillPop: () async { diff --git a/lib/ui/screens/main/pre_auth/pre_auth_main_screen.dart b/lib/ui/screens/main/pre_auth/pre_auth_main_screen.dart index 87101de4..acca5adf 100644 --- a/lib/ui/screens/main/pre_auth/pre_auth_main_screen.dart +++ b/lib/ui/screens/main/pre_auth/pre_auth_main_screen.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:another_flushbar/flushbar.dart'; import 'package:auto_route/auto_route.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; @@ -27,7 +28,7 @@ class PreAuthMainScreen extends StatefulWidget { class _PreAuthMainScreenState extends State { StreamSubscription? subscription; - final noConnectionMessage = noConnectionFlushbar(isPreAuth: true); + Flushbar? noConnectionMessage; static const analyticsTabNames = [ 'PreAuthPreventionTab', @@ -37,9 +38,11 @@ class _PreAuthMainScreenState extends State { void evalConnectivity(ConnectivityResult result) { if (result == ConnectivityResult.none) { - noConnectionMessage.show(context); - } else { - noConnectionMessage.dismiss(context); + if (noConnectionMessage?.isShowing() == false) { + noConnectionMessage?.show(context); + } + } else if (noConnectionMessage?.isDismissed() == false) { + noConnectionMessage?.dismiss(context); } } @@ -51,26 +54,18 @@ class _PreAuthMainScreenState extends State { evalConnectivity, ); - subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { - evalConnectivity(result); - - /// re-evaluate connection status after network reconnection - if (result != ConnectivityResult.none) { - Connectivity().checkConnectivity().then( - evalConnectivity, - ); - } - }); + subscription = Connectivity().onConnectivityChanged.listen(evalConnectivity); } @override void dispose() { - super.dispose(); subscription?.cancel(); + super.dispose(); } @override Widget build(BuildContext context) { + noConnectionMessage ??= noConnectionFlushbar(context: context, isPreAuth: true); return WillPopScope( onWillPop: () async { final webViewController = context.read().webViewController; diff --git a/lib/ui/widgets/no_connection_message.dart b/lib/ui/widgets/no_connection_message.dart index 8ace9b2a..4d2d2910 100644 --- a/lib/ui/widgets/no_connection_message.dart +++ b/lib/ui/widgets/no_connection_message.dart @@ -2,9 +2,10 @@ import 'package:another_flushbar/flushbar.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:loono/constants.dart'; +import 'package:loono/l10n/ext.dart'; import 'package:loono/ui/widgets/custom_navigation_bar.dart'; -Flushbar noConnectionFlushbar({bool isPreAuth = false}) { +Flushbar noConnectionFlushbar({bool isPreAuth = false, required BuildContext context}) { return Flushbar( forwardAnimationCurve: Curves.decelerate, reverseAnimationCurve: Curves.easeOut, @@ -15,8 +16,8 @@ Flushbar noConnectionFlushbar({bool isPreAuth = false}) { color: Colors.white, ), // hardcoded strings here don't need context - title: 'Žádné připojení', - message: 'Prosím zkontroluj své připojení k síti', + title: context.l10n.no_connection_message, + message: context.l10n.no_connection_message_check_connection, backgroundColor: LoonoColors.red, flushbarStyle: FlushbarStyle.FLOATING, flushbarPosition: isPreAuth ? FlushbarPosition.TOP : FlushbarPosition.BOTTOM, diff --git a/pubspec.lock b/pubspec.lock index fa495d8b..014813df 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1038,7 +1038,6 @@ packages: path: dart ref: "0ff983c382f3e33e3e096e6e88605e052b5ceadb" resolved-ref: "0ff983c382f3e33e3e096e6e88605e052b5ceadb" - url: "https://github.com/Loono-cz/loono-api.git" source: git version: "1.0.0"