Skip to content

Commit

Permalink
fix/zobrazeni_chybove_hlasky_pripojeni_k_internetu (#373)
Browse files Browse the repository at this point in the history
Oprava zobrazení chybové hlášky o připojení k internetu
Zlepšení způsobu zabránění dvojitého stahování prohlídek
Lokalizování textů v no_connection_message.dart
(Loono-cz/loono-tasks#92)
  • Loading branch information
Brambora0 committed Oct 5, 2022
1 parent 08d326f commit b64c03a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 49 deletions.
6 changes: 5 additions & 1 deletion lib/l10n/intl_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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":{}
}
51 changes: 22 additions & 29 deletions lib/ui/screens/main/main_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,63 +29,55 @@ class _MainScreenState extends State<MainScreen> {

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<ExaminationsProvider>(context, listen: false);
final examinationsProvider =
Provider.of<ExaminationsProvider>(context, listen: false);

WidgetsBinding.instance.addPostFrameCallback(
(_) => examinationsProvider.fetchExaminations(),
);
checkAndShowDonatePage(context, mounted: mounted);
registry.get<UserRepository>().sync();

/// lock connectivity for the first 300ms to prevent multiple api calls on init
Future<void>.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();
}
});
}

@override
void dispose() {
super.dispose();
subscription?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
final hasNotification =
context.select<ExaminationsProvider, bool>((state) => state.hasNotification);

noConnectionMessage ??= noConnectionFlushbar(context: context);
final hasNotification = context.select<ExaminationsProvider, bool>((state) => state.hasNotification);
return WillPopScope(
/// index 2 has its own WillPopScope for webview navigation. This prevents pop event override
onWillPop: () async {
Expand Down
25 changes: 10 additions & 15 deletions lib/ui/screens/main/pre_auth/pre_auth_main_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -27,7 +28,7 @@ class PreAuthMainScreen extends StatefulWidget {

class _PreAuthMainScreenState extends State<PreAuthMainScreen> {
StreamSubscription? subscription;
final noConnectionMessage = noConnectionFlushbar(isPreAuth: true);
Flushbar? noConnectionMessage;

static const analyticsTabNames = [
'PreAuthPreventionTab',
Expand All @@ -37,9 +38,11 @@ class _PreAuthMainScreenState extends State<PreAuthMainScreen> {

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);
}
}

Expand All @@ -51,26 +54,18 @@ class _PreAuthMainScreenState extends State<PreAuthMainScreen> {
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<WebViewProvider>().webViewController;
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/widgets/no_connection_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>(
forwardAnimationCurve: Curves.decelerate,
reverseAnimationCurve: Curves.easeOut,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b64c03a

Please sign in to comment.