Przeglądaj źródła

Update the base plugin for memories

Vishnu Mohandas 5 lat temu
rodzic
commit
8f2dce89c7
5 zmienionych plików z 124 dodań i 92 usunięć
  1. 15 11
      lib/ui/blurred_file_backdrop.dart
  2. 85 59
      lib/ui/memories_widget.dart
  3. 16 0
      lib/utils/file_util.dart
  4. 7 21
      pubspec.lock
  5. 1 1
      pubspec.yaml

+ 15 - 11
lib/ui/blurred_file_backdrop.dart

@@ -1,5 +1,6 @@
 import 'dart:ui';
 
+import 'package:animate_do/animate_do.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:photos/models/file.dart';
@@ -12,17 +13,20 @@ class BlurredFileBackdrop extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    return Stack(children: [
-      ThumbnailWidget(
-        file,
-        fit: BoxFit.cover,
-      ),
-      BackdropFilter(
-        filter: new ImageFilter.blur(sigmaX: 64.0, sigmaY: 64.0),
-        child: new Container(
-          decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
+    return FadeIn(
+      duration: Duration(milliseconds: 500),
+      child: Stack(children: [
+        ThumbnailWidget(
+          file,
+          fit: BoxFit.cover,
         ),
-      ),
-    ]);
+        BackdropFilter(
+          filter: new ImageFilter.blur(sigmaX: 64.0, sigmaY: 64.0),
+          child: new Container(
+            decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
+          ),
+        ),
+      ]),
+    );
   }
 }

+ 85 - 59
lib/ui/memories_widget.dart

@@ -1,10 +1,11 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
-import 'package:flutter_swiper/flutter_swiper.dart';
 import 'package:photos/memories_service.dart';
+import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/memory.dart';
 import 'package:photos/ui/blurred_file_backdrop.dart';
+import 'package:photos/ui/extents_page_view.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 import 'package:photos/ui/video_widget.dart';
 import 'package:photos/ui/zoomable_image.dart';
@@ -189,6 +190,7 @@ class FullScreenMemory extends StatefulWidget {
 class _FullScreenMemoryState extends State<FullScreenMemory> {
   int _index = 0;
   double _opacity = 1;
+  PageController _pageController;
 
   @override
   void initState() {
@@ -206,17 +208,18 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
 
   @override
   Widget build(BuildContext context) {
+    final file = widget.memories[_index].file;
     return Scaffold(
       appBar: AppBar(
-        title: Text(getFormattedDate(DateTime.fromMicrosecondsSinceEpoch(
-            widget.memories[_index].file.creationTime))),
+        title: Text(getFormattedDate(
+            DateTime.fromMicrosecondsSinceEpoch(file.creationTime))),
         backgroundColor: Color(0x00000000),
         elevation: 0,
         actions: [
           IconButton(
             icon: Icon(Icons.share),
             onPressed: () {
-              share(context, widget.memories[_index].file);
+              share(context, file);
             },
           ),
         ],
@@ -225,78 +228,101 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
       body: Container(
         color: Colors.black,
         child: Stack(children: [
+          BlurredFileBackdrop(file),
           _buildSwiper(),
-          Hero(
-            tag: widget.title,
-            child: Container(
-              alignment: Alignment.bottomCenter,
-              padding: EdgeInsets.fromLTRB(0, 0, 0, 160),
-              child: AnimatedOpacity(
-                opacity: _opacity,
-                duration: Duration(milliseconds: 500),
-                child: Material(
-                  type: MaterialType.transparency,
-                  child: Text(
-                    widget.title,
-                    style: TextStyle(
-                        fontSize: 40,
-                        fontWeight: FontWeight.bold,
-                        decoration: TextDecoration.none),
-                  ),
-                ),
-              ),
+          _buildTitleText(),
+          _buildIndexText(),
+        ]),
+      ),
+    );
+  }
+
+  Hero _buildTitleText() {
+    return Hero(
+      tag: widget.title,
+      child: Container(
+        alignment: Alignment.bottomCenter,
+        padding: EdgeInsets.fromLTRB(0, 0, 0, 160),
+        child: AnimatedOpacity(
+          opacity: _opacity,
+          duration: Duration(milliseconds: 500),
+          child: Material(
+            type: MaterialType.transparency,
+            child: Text(
+              widget.title,
+              style: TextStyle(
+                  fontSize: 40,
+                  fontWeight: FontWeight.bold,
+                  decoration: TextDecoration.none),
             ),
           ),
-        ]),
+        ),
       ),
     );
   }
 
-  Swiper _buildSwiper() {
-    return Swiper(
+  Widget _buildIndexText() {
+    return Container(
+      alignment: Alignment.bottomCenter,
+      padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
+      child: Text(
+        (_index + 1).toString() + " / " + widget.memories.length.toString(),
+        style: TextStyle(
+          fontSize: 24,
+          decoration: TextDecoration.none,
+          color: Colors.white60,
+        ),
+      ),
+    );
+  }
+
+  Widget _buildSwiper() {
+    _pageController = PageController(initialPage: _index);
+    return ExtentsPageView.extents(
       itemBuilder: (BuildContext context, int index) {
+        if (index < widget.memories.length - 1) {
+          final nextFile = widget.memories[index + 1].file;
+          preloadLocalFileThumbnail(nextFile);
+        }
         final file = widget.memories[index].file;
-        final view = file.fileType == FileType.image
-            ? ZoomableImage(
-                file,
-                tagPrefix: "memories",
-                backgroundDecoration: BoxDecoration(
-                  color: Colors.transparent,
-                ),
-              )
-            : VideoWidget(
-                file,
-                tagPrefix: "memories",
-                autoPlay: true,
-              );
-        return Stack(children: [
-          BlurredFileBackdrop(file),
-          view,
-        ]);
+        return MemoryItem(file);
       },
       itemCount: widget.memories.length,
-      pagination: SwiperPagination(
-          alignment: Alignment.bottomCenter,
-          margin: EdgeInsets.all(36),
-          builder: FractionPaginationBuilder(
-            activeColor: Colors.white,
-            color: Colors.grey,
-          )),
-      loop: false,
-      control: SwiperControl(
-        color: _opacity == 1 ? Colors.white54 : Colors.transparent,
-      ),
-      index: _index,
-      onIndexChanged: (index) async {
+      controller: _pageController,
+      extents: 2,
+      onPageChanged: (index) async {
         await MemoriesService.instance.markMemoryAsSeen(widget.memories[index]);
         setState(() {
           _index = index;
         });
-        if (index < widget.memories.length - 1) {
-          preloadFile(widget.memories[index + 1].file);
-        }
         return index;
       },
     );
   }
 }
+
+class MemoryItem extends StatelessWidget {
+  final File file;
+  const MemoryItem(this.file, {Key key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    final view = file.fileType == FileType.image
+        ? ZoomableImage(
+            file,
+            tagPrefix: "memories",
+            backgroundDecoration: BoxDecoration(
+              color: Colors.transparent,
+            ),
+          )
+        : VideoWidget(
+            file,
+            tagPrefix: "memories",
+            autoPlay: false,
+          );
+    return Stack(children: [
+      // BlurredFileBackdrop(file),
+      view,
+    ]);
+  }
+}

+ 16 - 0
lib/utils/file_util.dart

@@ -1,5 +1,7 @@
 import 'package:photo_manager/photo_manager.dart';
 import 'package:photos/core/cache/image_cache.dart';
+import 'package:photos/core/cache/thumbnail_cache.dart';
+import 'package:photos/core/constants.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
@@ -35,3 +37,17 @@ void preloadFile(File file) {
     }
   }
 }
+
+void preloadLocalFileThumbnail(File file) {
+  if (file.localId == null ||
+      ThumbnailLruCache.get(file, THUMBNAIL_SMALL_SIZE) != null) {
+    return;
+  }
+  file.getAsset().then((asset) {
+    asset
+        .thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
+        .then((data) {
+      ThumbnailLruCache.put(file, THUMBNAIL_SMALL_SIZE, data);
+    });
+  });
+}

+ 7 - 21
pubspec.lock

@@ -1,6 +1,13 @@
 # Generated by pub
 # See https://dart.dev/tools/pub/glossary#lockfile
 packages:
+  animate_do:
+    dependency: "direct main"
+    description:
+      name: animate_do
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.7.2"
   archive:
     dependency: "direct main"
     description:
@@ -230,20 +237,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.7.5"
-  flutter_page_indicator:
-    dependency: transitive
-    description:
-      name: flutter_page_indicator
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.0.3"
-  flutter_swiper:
-    dependency: "direct main"
-    description:
-      name: flutter_swiper
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.1.6"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -616,13 +609,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.2.17"
-  transformer_page_view:
-    dependency: transitive
-    description:
-      name: transformer_page_view
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.1.6"
   typed_data:
     dependency: transitive
     description:

+ 1 - 1
pubspec.yaml

@@ -54,7 +54,7 @@ dependencies:
   chewie: ^0.9.10
   cached_network_image: ^2.3.0-beta
   progress_dialog: ^1.2.4
-  flutter_swiper: ^1.1.6
+  animate_do: ^1.7.2
 
 dev_dependencies:
   flutter_test: