Browse Source

Extract common code to a function

Vishnu Mohandas 4 years ago
parent
commit
7f470fe817
1 changed files with 13 additions and 16 deletions
  1. 13 16
      lib/ui/create_collection_page.dart

+ 13 - 16
lib/ui/create_collection_page.dart

@@ -131,14 +131,7 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
         onTap: () async {
         onTap: () async {
           if (await _addToCollection(item.collection.id)) {
           if (await _addToCollection(item.collection.id)) {
             showToast("added successfully to '" + item.collection.name);
             showToast("added successfully to '" + item.collection.name);
-            Navigator.pop(context);
-            Navigator.push(
-                context,
-                PageTransition(
-                    type: PageTransitionType.bottomToTop,
-                    child: CollectionPage(
-                      item.collection,
-                    )));
+            _navigateToCollection(item.collection);
           }
           }
         },
         },
       ),
       ),
@@ -197,14 +190,7 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
             if (collection != null) {
             if (collection != null) {
               if (await _addToCollection(collection.id)) {
               if (await _addToCollection(collection.id)) {
                 showToast("album '" + _albumName + "' created.");
                 showToast("album '" + _albumName + "' created.");
-                Navigator.pop(context);
-                Navigator.push(
-                    context,
-                    PageTransition(
-                        type: PageTransitionType.bottomToTop,
-                        child: CollectionPage(
-                          collection,
-                        )));
+                _navigateToCollection(collection);
               }
               }
             }
             }
           },
           },
@@ -220,6 +206,17 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
     );
     );
   }
   }
 
 
+  void _navigateToCollection(Collection collection) {
+    Navigator.pop(context);
+    Navigator.push(
+        context,
+        PageTransition(
+            type: PageTransitionType.bottomToTop,
+            child: CollectionPage(
+              collection,
+            )));
+  }
+
   Future<bool> _addToCollection(int collectionID) async {
   Future<bool> _addToCollection(int collectionID) async {
     final dialog = createProgressDialog(context, "uploading files to album...");
     final dialog = createProgressDialog(context, "uploading files to album...");
     await dialog.show();
     await dialog.show();