diff --git a/lib/main.dart b/lib/main.dart index fc42683..84357e2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -216,6 +216,7 @@ class _LoginPageState extends State { try { var l = await canteen.login(r["user"]!, r["pass"]!); if (!l) { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -226,6 +227,7 @@ class _LoginPageState extends State { } const storage = FlutterSecureStorage(); var odsouhlasil = await storage.read(key: "oc_souhlas"); + if (!mounted) return; if (odsouhlasil == null || odsouhlasil != "ano") { Navigator.pushReplacement( context, @@ -241,6 +243,7 @@ class _LoginPageState extends State { ); } } on PlatformException { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -248,6 +251,7 @@ class _LoginPageState extends State { ), ); } catch (_) { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -343,13 +347,14 @@ class _LoginPageState extends State { if (!canteenControl.text.startsWith("https://") && !canteenControl.text.startsWith("http://")) { canteenControl.text = - "https://" + canteenControl.text; + "https://${canteenControl.text}"; } var canteen = Canteen(canteenControl.text); try { var l = await canteen.login( userControl.text, passControl.text); if (!l) { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -367,6 +372,7 @@ class _LoginPageState extends State { const storage = FlutterSecureStorage(); var odsouhlasil = await storage.read(key: "oc_souhlas"); + if (!mounted) return; if (odsouhlasil == null || odsouhlasil != "ano") { Navigator.pushReplacement( context, @@ -384,6 +390,7 @@ class _LoginPageState extends State { ); } } on PlatformException { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -391,6 +398,7 @@ class _LoginPageState extends State { ), ); } on Exception catch (_) { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -413,8 +421,8 @@ class _LoginPageState extends State { void goOffline() async { Directory appDocDir = await getApplicationDocumentsDirectory(); var den = DateTime.now(); - var soubor = File(appDocDir.path + - "/jidelnicek_${den.year}-${den.month}-${den.day}.json"); + var soubor = File( + "${appDocDir.path}/jidelnicek_${den.year}-${den.month}-${den.day}.json"); if (soubor.existsSync()) { // načteme offline jídelníček var input = await soubor.readAsString(); @@ -429,6 +437,7 @@ class _LoginPageState extends State { naBurze: j["naBurze"], den: DateTime.parse(j["den"]))); } + if (!mounted) return; Navigator.pushReplacement( context, MaterialPageRoute( diff --git a/lib/okna/about.dart b/lib/okna/about.dart index f01b4fb..b62b7f1 100644 --- a/lib/okna/about.dart +++ b/lib/okna/about.dart @@ -26,8 +26,8 @@ class _AboutPageState extends State { const Text("OpenCanteen", style: TextStyle(fontSize: 30)), Text(Languages.of(context)!.copyright), InkWell( - onTap: () => launch( - "https://github.com/hernikplays/opencanteen/blob/main/LICENSE"), + onTap: () => launchUrl(Uri.parse( + "https://github.com/hernikplays/opencanteen/blob/main/LICENSE")), child: Text(Languages.of(context)!.license)), const SizedBox(height: 15), Text(Languages.of(context)!.usedLibs, @@ -91,7 +91,7 @@ class _AboutPageState extends State { Widget cudlik(String nazev, String copyright, String licence) { return InkWell( - onTap: () => launch(licence), + onTap: () => launchUrl(Uri.parse(licence)), child: Column(children: [ Text( nazev, diff --git a/lib/okna/jidelnicek.dart b/lib/okna/jidelnicek.dart index 444cd0a..fa6ba34 100644 --- a/lib/okna/jidelnicek.dart +++ b/lib/okna/jidelnicek.dart @@ -39,6 +39,7 @@ class _JidelnicekPageState extends State { var jidelnicek = await widget.canteen.jidelnicekDen(den: pristi); if (jidelnicek.jidla.isNotEmpty && !jidelnicek.jidla.any((element) => element.objednano == true)) { + if (!mounted) return; ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -328,7 +329,8 @@ class _JidelnicekPageState extends State { ), ); } else if (value == Languages.of(context)!.reportBugs) { - launch("https://github.com/hernikplays/opencanteen/issues/new/choose"); + launchUrl(Uri.parse( + "https://github.com/hernikplays/opencanteen/issues/new/choose")); } else if (value == Languages.of(context)!.about) { Navigator.push( context, MaterialPageRoute(builder: (c) => const AboutPage())); @@ -356,8 +358,8 @@ class _JidelnicekPageState extends State { } // Uložíme nová data var j = await widget.canteen.jidelnicekDen(); - var soubor = File(appDocDir.path + - "/jidelnicek_${den.year}-${den.month}-${den.day}.json"); + var soubor = File( + "${appDocDir.path}/jidelnicek_${den.year}-${den.month}-${den.day}.json"); soubor.createSync(); var jidla = []; for (var jidlo in j.jidla) { @@ -408,8 +410,10 @@ class _JidelnicekPageState extends State { ], ), body: RefreshIndicator( + onRefresh: nactiJidlo, child: Center( child: SizedBox( + width: MediaQuery.of(context).size.width - 50, child: Column( children: [ const SizedBox(height: 10), @@ -470,8 +474,8 @@ class _JidelnicekPageState extends State { .colorScheme .onPrimary .withOpacity(0), - child: Column(children: obsah), height: MediaQuery.of(context).size.height / 1.3, + child: Column(children: obsah), ), onHorizontalDragEnd: (details) { if (details.primaryVelocity?.compareTo(0) == -1) { @@ -496,10 +500,8 @@ class _JidelnicekPageState extends State { ) ], ), - width: MediaQuery.of(context).size.width - 50, ), ), - onRefresh: nactiJidlo, ), ); } diff --git a/lib/okna/nastaveni.dart b/lib/okna/nastaveni.dart index f2d2fe3..4839240 100644 --- a/lib/okna/nastaveni.dart +++ b/lib/okna/nastaveni.dart @@ -37,14 +37,14 @@ class _NastaveniState extends State { _preskakovatVikend = preferences.getBool("skip") ?? false; _kontrolovatTyden = preferences.getBool("tyden") ?? false; _oznameniObed = preferences.getBool("oznamit") ?? false; - var _casStr = preferences.getString("oznameni_cas"); - if (_casStr == null) { + var casStr = preferences.getString("oznameni_cas"); + if (casStr == null) { var now = DateTime.now(); _oznameniCas = TimeOfDay.fromDateTime( DateTime.now().add(const Duration(hours: 1))); preferences.setString("oznameni_cas", now.toString()); } else { - _oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(_casStr)); + _oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(casStr)); } }); } @@ -236,6 +236,7 @@ class _NastaveniState extends State { IOSNotificationDetails(presentAlert: true, presentBadge: true); var l = tz.getLocation(await FlutterNativeTimezone.getLocalTimezone()); + if (!mounted) return; await widget.n.zonedSchedule( // Vytvoří nové oznámení pro daný čas a datum 0, diff --git a/lib/okna/offline_jidelnicek.dart b/lib/okna/offline_jidelnicek.dart index 59229f1..d4bf0ec 100644 --- a/lib/okna/offline_jidelnicek.dart +++ b/lib/okna/offline_jidelnicek.dart @@ -82,7 +82,8 @@ class _OfflineJidelnicekState extends State { Navigator.pushReplacement( context, MaterialPageRoute(builder: (c) => const LoginPage())); } else if (value == Languages.of(context)!.reportBugs) { - launch("https://github.com/hernikplays/opencanteen/issues/new/choose"); + launchUrl(Uri.parse( + "https://github.com/hernikplays/opencanteen/issues/new/choose")); } else if (value == Languages.of(context)!.about) { Navigator.push( context, MaterialPageRoute(builder: (c) => const AboutPage())); @@ -122,6 +123,7 @@ class _OfflineJidelnicekState extends State { body: RefreshIndicator( child: Center( child: SizedBox( + width: MediaQuery.of(context).size.width - 50, child: Column( children: [ const SizedBox(height: 10), @@ -144,7 +146,6 @@ class _OfflineJidelnicekState extends State { ), ], ), - width: MediaQuery.of(context).size.width - 50, ), ), onRefresh: () => Navigator.pushReplacement(context, diff --git a/lib/okna/welcome.dart b/lib/okna/welcome.dart index 36d555c..bae4aaa 100644 --- a/lib/okna/welcome.dart +++ b/lib/okna/welcome.dart @@ -69,6 +69,7 @@ class _WelcomeScreenState extends State { onDone: () async { const storage = FlutterSecureStorage(); await storage.write(key: "oc_souhlas", value: "ano"); + if (!mounted) return; Navigator.of(context).pushReplacement(MaterialPageRoute( builder: (c) => JidelnicekPage(canteen: widget.canteen, n: widget.n))); diff --git a/pubspec.lock b/pubspec.lock index b1df825..dfc85a0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,42 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "3.3.0" + version: "3.3.1" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.3.1" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" canteenlib: dependency: "direct main" description: name: canteenlib url: "https://pub.dartlang.org" source: hosted - version: "0.1.0-alpha.16" + version: "1.0.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -63,14 +56,14 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" dbus: dependency: transitive description: name: dbus url: "https://pub.dartlang.org" source: hosted - version: "0.7.2" + version: "0.7.8" dots_indicator: dependency: transitive description: @@ -84,14 +77,14 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "2.0.1" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -103,28 +96,28 @@ packages: name: flutter_launcher_icons url: "https://pub.dartlang.org" source: hosted - version: "0.9.2" + version: "0.9.3" flutter_lints: dependency: "direct dev" description: name: flutter_lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.1" flutter_local_notifications: dependency: "direct main" description: name: flutter_local_notifications url: "https://pub.dartlang.org" source: hosted - version: "9.5.3+1" + version: "9.9.1" flutter_local_notifications_linux: dependency: transitive description: name: flutter_local_notifications_linux url: "https://pub.dartlang.org" source: hosted - version: "0.4.2" + version: "0.5.1" flutter_local_notifications_platform_interface: dependency: transitive description: @@ -150,21 +143,21 @@ packages: name: flutter_secure_storage url: "https://pub.dartlang.org" source: hosted - version: "5.0.2" + version: "5.1.2" flutter_secure_storage_linux: dependency: transitive description: name: flutter_secure_storage_linux url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" flutter_secure_storage_macos: dependency: transitive description: name: flutter_secure_storage_macos url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" flutter_secure_storage_platform_interface: dependency: transitive description: @@ -197,23 +190,23 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.4" + version: "0.13.5" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image: dependency: transitive description: name: image url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" + version: "3.2.0" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" @@ -239,84 +232,84 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.0.0" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" path_provider: dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.11" path_provider_android: dependency: transitive description: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.12" + version: "2.0.20" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.11" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.7" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.3" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "5.0.0" platform: dependency: transitive description: @@ -344,56 +337,56 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "2.0.13" + version: "2.0.15" shared_preferences_android: dependency: transitive description: name: shared_preferences_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" + version: "2.0.12" shared_preferences_ios: dependency: transitive description: name: shared_preferences_ios url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" sky_engine: dependency: transitive description: flutter @@ -405,21 +398,21 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" timezone: dependency: "direct main" description: @@ -433,63 +426,63 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.20" + version: "6.1.5" url_launcher_android: dependency: transitive description: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.15" + version: "6.0.17" url_launcher_ios: dependency: transitive description: name: url_launcher_ios url: "https://pub.dartlang.org" source: hosted - version: "6.0.15" + version: "6.0.17" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.0" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.13" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" vector_math: dependency: transitive description: @@ -503,28 +496,28 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.5.2" + version: "3.0.0" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+1" + version: "0.2.0+2" xml: dependency: transitive description: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.3.1" + version: "6.1.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "3.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" - flutter: ">=2.10.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8ecafd0..44b96b2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter - canteenlib: ^0.1.0-alpha.16 + canteenlib: ^1.0.0 flutter_secure_storage: ^5.0.2 url_launcher: ^6.0.20 path_provider: ^2.0.9 @@ -25,9 +25,10 @@ dependencies: flutter_local_notifications: ^9.5.3+1 timezone: ^0.8.0 flutter_native_timezone: ^2.0.0 + intl: ^0.17.0 dev_dependencies: - flutter_lints: ^1.0.0 + flutter_lints: ^2.0.1 flutter_launcher_icons: "^0.9.2" flutter_icons: