Browse Source

Fix dialog dismissals

Vishnu Mohandas 4 years ago
parent
commit
a4fd2f7cf4

+ 20 - 12
lib/services/collections_service.dart

@@ -177,18 +177,26 @@ class CollectionsService {
     SyncService.instance.syncWithRemote(silently: true);
   }
 
-  Future<void> unshare(int collectionID, String email) {
-    return _dio
-        .post(
-          Configuration.instance.getHttpEndpoint() + "/collections/unshare",
-          data: {
-            "collectionID": collectionID,
-            "email": email,
-          },
-          options: Options(
-              headers: {"X-Auth-Token": Configuration.instance.getToken()}),
-        )
-        .then((value) => SyncService.instance.syncWithRemote(silently: true));
+  Future<void> unshare(int collectionID, String email) async {
+    try {
+      await _dio.post(
+        Configuration.instance.getHttpEndpoint() + "/collections/unshare",
+        data: {
+          "collectionID": collectionID,
+          "email": email,
+        },
+        options: Options(
+            headers: {"X-Auth-Token": Configuration.instance.getToken()}),
+      );
+      _collectionIDToCollections[collectionID]
+          .sharees
+          .removeWhere((user) => user.email == email);
+      _db.insert([_collectionIDToCollections[collectionID]]);
+    } catch (e) {
+      _logger.severe(e);
+      throw e;
+    }
+    SyncService.instance.syncWithRemote(silently: true);
   }
 
   Uint8List getCollectionKey(int collectionID) {

+ 1 - 1
lib/ui/create_collection_page.dart

@@ -185,7 +185,7 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
         FlatButton(
           child: Text("ok"),
           onPressed: () async {
-            Navigator.pop(context);
+            Navigator.of(context, rootNavigator: true).pop('dialog');
             final collection = await _createAlbum(_albumName);
             if (collection != null) {
               if (await _addToCollection(collection.id)) {

+ 1 - 1
lib/ui/detail_page.dart

@@ -326,7 +326,7 @@ class _DetailPageState extends State<DetailPage> {
             FlatButton(
               child: Text('ok'),
               onPressed: () {
-                Navigator.of(context).pop();
+                Navigator.of(context, rootNavigator: true).pop('dialog');
               },
             ),
           ],

+ 1 - 2
lib/ui/gallery_app_bar_widget.dart

@@ -231,6 +231,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
           child: Text("remove"),
           isDestructiveAction: true,
           onPressed: () async {
+            Navigator.of(context, rootNavigator: true).pop();
             final dialog = createProgressDialog(context, "removing files...");
             await dialog.show();
             try {
@@ -238,11 +239,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
                   widget.collection.id, widget.selectedFiles.files.toList());
               await dialog.hide();
               widget.selectedFiles.clearAll();
-              Navigator.of(context).pop();
             } catch (e, s) {
               _logger.severe(e, s);
               await dialog.hide();
-              Navigator.of(context).pop();
               showGenericErrorDialog(context);
             }
           },

+ 1 - 1
lib/ui/home_widget.dart

@@ -105,7 +105,7 @@ class _HomeWidgetState extends State<HomeWidget> {
               ),
             ),
             onPressed: () async {
-              Navigator.of(context).pop();
+              Navigator.of(context, rootNavigator: true).pop('dialog');
               final dialog = createProgressDialog(context, "logging out...");
               await dialog.show();
               await Configuration.instance.logout();

+ 2 - 2
lib/ui/password_entry_page.dart

@@ -160,13 +160,13 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
         FlatButton(
           child: Text("change"),
           onPressed: () {
-            Navigator.of(context).pop();
+            Navigator.of(context, rootNavigator: true).pop();
           },
         ),
         FlatButton(
           child: Text("confirm"),
           onPressed: () {
-            Navigator.of(context).pop();
+            Navigator.of(context, rootNavigator: true).pop();
             UserService.instance
                 .setupAttributes(context, _passwordController1.text);
           },

+ 5 - 5
lib/ui/settings_page.dart

@@ -76,7 +76,7 @@ class SettingsPage extends StatelessWidget {
         },
       ),
     );
-    if (kDebugMode) {
+    if (kDebugMode && hasLoggedIn) {
       contents.add(DebugWidget());
     }
     return SingleChildScrollView(
@@ -188,7 +188,7 @@ class BackupSettingsWidgetState extends State<BackupSettingsWidget> {
         FlatButton(
           child: Text("OK"),
           onPressed: () {
-            Navigator.of(context).pop();
+            Navigator.of(context, rootNavigator: true).pop('dialog');
           },
         ),
       ],
@@ -515,7 +515,7 @@ class AccountSectionWidget extends StatelessWidget {
                     ),
                   ),
                   onPressed: () {
-                    Navigator.of(context).pop();
+                    Navigator.of(context, rootNavigator: true).pop('dialog');
                   },
                 ),
                 TextButton(
@@ -566,7 +566,7 @@ class DebugWidget extends StatelessWidget {
             _showKeyAttributesDialog(context);
           },
           child: SettingsTextItem(
-              text: "Key Attributes", icon: Icons.navigate_next),
+              text: "key attributes", icon: Icons.navigate_next),
         ),
       ]),
     );
@@ -597,7 +597,7 @@ class DebugWidget extends StatelessWidget {
         FlatButton(
           child: Text("OK"),
           onPressed: () {
-            Navigator.of(context).pop();
+            Navigator.of(context, rootNavigator: true).pop('dialog');
           },
         ),
       ],

+ 7 - 6
lib/ui/share_collection_widget.dart

@@ -41,7 +41,7 @@ class _SharingDialogState extends State<SharingDialog> {
       _showEntryField = true;
     } else {
       for (final user in _sharees) {
-        children.add(EmailItemWidget(widget.collection.id, user.email));
+        children.add(EmailItemWidget(widget.collection, user.email));
       }
     }
     if (_showEntryField) {
@@ -169,7 +169,7 @@ class _SharingDialogState extends State<SharingDialog> {
       await dialog.hide();
     }
     if (publicKey == null) {
-      Navigator.of(context).pop();
+      Navigator.of(context, rootNavigator: true).pop('dialog');
       final dialog = AlertDialog(
         title: Text("Invite to ente?"),
         content: Text("Looks like " +
@@ -234,7 +234,7 @@ class _SharingDialogState extends State<SharingDialog> {
               FlatButton(
                 child: Text("ok"),
                 onPressed: () {
-                  Navigator.of(context).pop();
+                  Navigator.of(context, rootNavigator: true).pop();
                 },
               ),
             ],
@@ -255,11 +255,11 @@ class _SharingDialogState extends State<SharingDialog> {
 }
 
 class EmailItemWidget extends StatelessWidget {
-  final int collectionID;
+  final Collection collection;
   final String email;
 
   const EmailItemWidget(
-    this.collectionID,
+    this.collection,
     this.email, {
     Key key,
   }) : super(key: key);
@@ -284,7 +284,8 @@ class EmailItemWidget extends StatelessWidget {
             final dialog = createProgressDialog(context, "please wait...");
             await dialog.show();
             try {
-              await CollectionsService.instance.unshare(collectionID, email);
+              await CollectionsService.instance.unshare(collection.id, email);
+              collection.sharees.removeWhere((user) => user.email == email);
               await dialog.hide();
               showToast("stopped sharing with " + email + ".");
               Navigator.of(context).pop();

+ 4 - 32
lib/ui/subscription_page.dart

@@ -437,18 +437,19 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
               Row(
                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
                 children: [
-                  FlatButton(
+                  TextButton(
                     child: Text("review plans"),
                     onPressed: () {
-                      Navigator.of(context).pop();
+                      Navigator.of(context, rootNavigator: true).pop('dialog');
                     },
                   ),
-                  FlatButton(
+                  TextButton(
                     child: Text("ok"),
                     onPressed: () {
                       if (widget.isOnboarding) {
                         Bus.instance.fire(SubscriptionPurchasedEvent());
                       }
+                      Navigator.of(context, rootNavigator: true).pop('dialog');
                       Navigator.of(context).popUntil((route) => route.isFirst);
                     },
                   ),
@@ -674,32 +675,3 @@ class SubscriptionPlanWidget extends StatelessWidget {
     );
   }
 }
-
-class SubsriptionSuccessfulDialog extends StatelessWidget {
-  const SubsriptionSuccessfulDialog({Key key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return AlertDialog(
-      title: Text("success!",
-          style: TextStyle(
-            fontWeight: FontWeight.bold,
-          )),
-      content: SingleChildScrollView(
-        child: Column(children: [
-          Text("your photos and videos will now be backed up"),
-          Padding(padding: EdgeInsets.all(6)),
-          Text("the first sync might take a while, please bear with us"),
-        ]),
-      ),
-      actions: [
-        FlatButton(
-          child: Text("ok"),
-          onPressed: () {
-            Navigator.of(context).pop();
-          },
-        ),
-      ],
-    );
-  }
-}

+ 1 - 1
lib/utils/dialog_util.dart

@@ -29,7 +29,7 @@ void showErrorDialog(BuildContext context, String title, String content) {
       FlatButton(
         child: Text("ok"),
         onPressed: () {
-          Navigator.of(context).pop();
+          Navigator.of(context, rootNavigator: true).pop('dialog');
         },
       ),
     ],