Bläddra i källkod

Add error states to deal with no-network situations

Vishnu Mohandas 4 år sedan
förälder
incheckning
5d65eb2e05
2 ändrade filer med 27 tillägg och 44 borttagningar
  1. 27 10
      lib/ui/gallery_app_bar_widget.dart
  2. 0 34
      lib/ui/share_collection_widget.dart

+ 27 - 10
lib/ui/gallery_app_bar_widget.dart

@@ -14,7 +14,7 @@ import 'package:photos/ui/email_entry_page.dart';
 import 'package:photos/ui/passphrase_entry_page.dart';
 import 'package:photos/ui/passphrase_entry_page.dart';
 import 'package:photos/ui/passphrase_reentry_page.dart';
 import 'package:photos/ui/passphrase_reentry_page.dart';
 import 'package:photos/ui/settings_page.dart';
 import 'package:photos/ui/settings_page.dart';
-import 'package:photos/ui/share_folder_widget.dart';
+import 'package:photos/ui/share_collection_widget.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/share_util.dart';
 import 'package:photos/utils/share_util.dart';
@@ -158,21 +158,38 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
         if (collection == null) {
         if (collection == null) {
           final dialog = createProgressDialog(context, "Please wait...");
           final dialog = createProgressDialog(context, "Please wait...");
           await dialog.show();
           await dialog.show();
-          collection =
-              await CollectionsService.instance.getOrCreateForPath(widget.path);
-          await dialog.hide();
+          try {
+            collection = await CollectionsService.instance
+                .getOrCreateForPath(widget.path);
+            await dialog.hide();
+          } catch (e, s) {
+            _logger.severe(e, s);
+            await dialog.hide();
+            showGenericErrorDialog(context);
+          }
         }
         }
       } else {
       } else {
         throw Exception(
         throw Exception(
             "Cannot create a collection of type" + widget.type.toString());
             "Cannot create a collection of type" + widget.type.toString());
       }
       }
     }
     }
-    return showDialog<void>(
-      context: context,
-      builder: (BuildContext context) {
-        return ShareFolderWidget(collection);
-      },
-    );
+    final dialog = createProgressDialog(context, "Please wait...");
+    await dialog.show();
+    try {
+      final sharees =
+          await CollectionsService.instance.getSharees(widget.collection.id);
+      await dialog.hide();
+      return showDialog<void>(
+        context: context,
+        builder: (BuildContext context) {
+          return SharingDialog(collection, sharees);
+        },
+      );
+    } catch (e, s) {
+      _logger.severe(e, s);
+      await dialog.hide();
+      showGenericErrorDialog(context);
+    }
   }
   }
 
 
   Future<void> _createAlbum() async {
   Future<void> _createAlbum() async {

+ 0 - 34
lib/ui/share_folder_widget.dart → lib/ui/share_collection_widget.dart

@@ -1,7 +1,6 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter/widgets.dart';
-import 'package:flutter_sodium/flutter_sodium.dart';
 import 'package:flutter_typeahead/flutter_typeahead.dart';
 import 'package:flutter_typeahead/flutter_typeahead.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/db/public_keys_db.dart';
 import 'package:photos/db/public_keys_db.dart';
@@ -12,44 +11,11 @@ import 'package:photos/services/sync_service.dart';
 import 'package:photos/services/user_service.dart';
 import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/common_elements.dart';
 import 'package:photos/ui/common_elements.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/loading_widget.dart';
-import 'package:photos/utils/crypto_util.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/email_util.dart';
 import 'package:photos/utils/email_util.dart';
 import 'package:photos/utils/share_util.dart';
 import 'package:photos/utils/share_util.dart';
 import 'package:photos/utils/toast_util.dart';
 import 'package:photos/utils/toast_util.dart';
 
 
-class ShareFolderWidget extends StatefulWidget {
-  final Collection collection;
-
-  const ShareFolderWidget(
-    this.collection, {
-    Key key,
-  }) : super(key: key);
-
-  @override
-  _ShareFolderWidgetState createState() => _ShareFolderWidgetState();
-}
-
-class _ShareFolderWidgetState extends State<ShareFolderWidget> {
-  @override
-  Widget build(BuildContext context) {
-    return FutureBuilder<List<String>>(
-      future: widget.collection == null
-          ? Future.value(List<String>())
-          : CollectionsService.instance.getSharees(widget.collection.id),
-      builder: (context, snapshot) {
-        if (snapshot.hasData) {
-          return SharingDialog(widget.collection, snapshot.data);
-        } else if (snapshot.hasError) {
-          return Text(snapshot.error.toString());
-        } else {
-          return loadWidget;
-        }
-      },
-    );
-  }
-}
-
 class SharingDialog extends StatefulWidget {
 class SharingDialog extends StatefulWidget {
   final Collection collection;
   final Collection collection;
   final List<String> sharees;
   final List<String> sharees;