diff --git a/lib/drawer/nav_drawer.dart b/lib/drawer/nav_drawer.dart index 14678048..e40e9d3a 100644 --- a/lib/drawer/nav_drawer.dart +++ b/lib/drawer/nav_drawer.dart @@ -66,8 +66,8 @@ class _NavDrawerState extends State { color: AppSettings.isDarkMode ? Colors.white : Colors.black, ), onTap: () { - storageWidget.synchronize(context); Navigator.pop(context); + storageWidget.synchronize(context, true); }, title: const Text("Refresh"), ), diff --git a/lib/model/storage/storage_widget.dart b/lib/model/storage/storage_widget.dart index ffc47604..69313ed8 100644 --- a/lib/model/storage/storage_widget.dart +++ b/lib/model/storage/storage_widget.dart @@ -1,6 +1,9 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:collection'; import 'dart:io'; +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:flutter/material.dart'; import 'package:loggy/loggy.dart'; @@ -241,18 +244,67 @@ class _StorageWidgetState extends State { setState(() {}); } - Future synchronize(BuildContext context) async { + Future synchronize(BuildContext context, bool isDialogNeeded) async { try { - var header = await storage.home.synchronize(await client()); - _refreshTasks(); - pendingTags = _pendingTags(); - projects = _projects(); - setState(() {}); - // ignore: use_build_context_synchronously - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('${header['code']}: ${header['status']}'), - )); - // ignore: avoid_catches_without_on_clauses + final connectivityResult = await Connectivity().checkConnectivity(); + if (connectivityResult == ConnectivityResult.none) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text( + 'You are not connected to the internet. Please check your network connection.'), + ), + ); + } else { + if (isDialogNeeded) { + showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return Dialog( + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ), + child: Container( + padding: const EdgeInsets.all(16.0), + child: const Column( + mainAxisSize: MainAxisSize.min, + children: [ + CircularProgressIndicator(), + SizedBox(height: 16.0), + Text( + "Syncing", + style: TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 8.0), + Text("Please wait..."), + ], + ), + ), + ); + }, + ); + } + + var header = await storage.home.synchronize(await client()); + _refreshTasks(); + pendingTags = _pendingTags(); + projects = _projects(); + setState(() {}); + + if (isDialogNeeded) { + Navigator.pop(context); + } + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('${header['code']}: ${header['status']}'), + ), + ); + } } catch (e, trace) { logError(e, trace); } @@ -412,7 +464,7 @@ class InheritedStorage extends InheritedModel { final Set selectedTags; final Task Function(String) getTask; final void Function(Task) mergeTask; - final void Function(BuildContext) synchronize; + final void Function(BuildContext, bool) synchronize; final void Function() togglePendingFilter; final void Function(String) toggleProjectFilter; final void Function() toggleTagUnion; diff --git a/lib/views/home/home.dart b/lib/views/home/home.dart index b470830d..0052162c 100644 --- a/lib/views/home/home.dart +++ b/lib/views/home/home.dart @@ -68,7 +68,7 @@ class _HomePageState extends State { if (value) { storageWidget = StorageWidget.of(context); - storageWidget.synchronize(context); + storageWidget.synchronize(context, false); } else {} } @@ -129,7 +129,7 @@ class _HomePageState extends State { Builder( builder: (context) => IconButton( icon: const Icon(Icons.refresh, color: Colors.white), - onPressed: () => storageWidget.synchronize(context), + onPressed: () => storageWidget.synchronize(context, true), ), ), Builder( diff --git a/pubspec.lock b/pubspec.lock index 6311e73d..e923acc1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -157,10 +157,26 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.17.2" + connectivity_plus: + dependency: "direct main" + description: + name: connectivity_plus + sha256: "77a180d6938f78ca7d2382d2240eb626c0f6a735d0bfdce227d8ffb80f95c48b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + connectivity_plus_platform_interface: + dependency: transitive + description: + name: connectivity_plus_platform_interface + sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a + url: "https://pub.dev" + source: hosted + version: "1.2.4" convert: dependency: transitive description: @@ -406,6 +422,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + flutter_svg: + dependency: "direct main" + description: + name: flutter_svg + sha256: "8c5d68a82add3ca76d792f058b186a0599414f279f00ece4830b9b231b570338" + url: "https://pub.dev" + source: hosted + version: "2.0.7" flutter_test: dependency: "direct dev" description: flutter @@ -596,18 +620,18 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" meta: dependency: transitive description: @@ -624,6 +648,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" + nm: + dependency: transitive + description: + name: nm + sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" + url: "https://pub.dev" + source: hosted + version: "0.5.0" package_config: dependency: transitive description: @@ -656,6 +688,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.8.3" + path_parsing: + dependency: transitive + description: + name: path_parsing + sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf + url: "https://pub.dev" + source: hosted + version: "1.0.1" path_provider: dependency: transitive description: @@ -756,10 +796,10 @@ packages: dependency: transitive description: name: petitparser - sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4" + sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750 url: "https://pub.dev" source: hosted - version: "5.1.0" + version: "5.4.0" platform: dependency: transitive description: @@ -896,6 +936,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" + sizer: + dependency: "direct main" + description: + name: sizer + sha256: d2b3cb6cbc4a637f508dacd786bae55df31e5fc088044248a43e4fd1e050c117 + url: "https://pub.dev" + source: hosted + version: "2.0.15" sky_engine: dependency: transitive description: flutter @@ -921,10 +969,10 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: @@ -993,10 +1041,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.0" timezone: dependency: "direct main" description: @@ -1045,6 +1093,70 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.0" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "47e208a6711459d813ba18af120d9663c20bdf6985d6ad39fe165d2538378d27" + url: "https://pub.dev" + source: hosted + version: "6.1.14" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: b04af59516ab45762b2ca6da40fa830d72d0f6045cd97744450b73493fa76330 + url: "https://pub.dev" + source: hosted + version: "6.1.0" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: "7c65021d5dee51813d652357bc65b8dd4a6177082a9966bc8ba6ee477baa795f" + url: "https://pub.dev" + source: hosted + version: "6.1.5" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: b651aad005e0cb06a01dbd84b428a301916dc75f0e7ea6165f80057fee2d8e8e + url: "https://pub.dev" + source: hosted + version: "3.0.6" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: b55486791f666e62e0e8ff825e58a023fd6b1f71c49926483f1128d3bbd8fe88 + url: "https://pub.dev" + source: hosted + version: "3.0.7" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "95465b39f83bfe95fcb9d174829d6476216f2d548b79c38ab2506e0458787618" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "2942294a500b4fa0b918685aff406773ba0a4cd34b7f42198742a94083020ce5" + url: "https://pub.dev" + source: hosted + version: "2.0.20" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "95fef3129dc7cfaba2bc3d5ba2e16063bb561fc6d78e63eee16162bc70029069" + url: "https://pub.dev" + source: hosted + version: "3.0.8" uuid: dependency: "direct main" description: @@ -1053,6 +1165,30 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.7" + vector_graphics: + dependency: transitive + description: + name: vector_graphics + sha256: "670f6e07aca990b4a2bcdc08a784193c4ccdd1932620244c3a86bb72a0eac67f" + url: "https://pub.dev" + source: hosted + version: "1.1.7" + vector_graphics_codec: + dependency: transitive + description: + name: vector_graphics_codec + sha256: "7451721781d967db9933b63f5733b1c4533022c0ba373a01bdd79d1a5457f69f" + url: "https://pub.dev" + source: hosted + version: "1.1.7" + vector_graphics_compiler: + dependency: transitive + description: + name: vector_graphics_compiler + sha256: "80a13c613c8bde758b1464a1755a7b3a8f2b6cec61fbf0f5a53c94c30f03ba2e" + url: "https://pub.dev" + source: hosted + version: "1.1.7" vector_math: dependency: transitive description: @@ -1069,6 +1205,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -1097,10 +1241,10 @@ packages: dependency: transitive description: name: xml - sha256: ac0e3f4bf00ba2708c33fbabbbe766300e509f8c82dbd4ab6525039813f7e2fb + sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "6.3.0" yaml: dependency: transitive description: @@ -1110,5 +1254,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=3.0.0 <4.0.0" - flutter: ">=3.3.0" + dart: ">=3.1.0 <4.0.0" + flutter: ">=3.13.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0b7b2621..c337f3b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,6 +12,7 @@ environment: # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: + connectivity_plus: ^4.0.2 cupertino_icons: ^1.0.5 date_format: ^2.0.6 double_back_to_close_app: ^2.1.0