浏览代码

Show actionbar for fewer photos too

Vishnu Mohandas 4 年之前
父节点
当前提交
3f3ff2192b
共有 2 个文件被更改,包括 50 次插入48 次删除
  1. 39 39
      lib/ui/gallery.dart
  2. 11 9
      lib/ui/home_widget.dart

+ 39 - 39
lib/ui/gallery.dart

@@ -158,46 +158,46 @@ class _GalleryState extends State<Gallery> {
         cacheExtent: 1500,
         addAutomaticKeepAlives: true,
       );
-      return gallery;
-    }
-    gallery = DraggableScrollbar.semicircle(
-      key: _scrollKey,
-      initialScrollIndex: _lastIndex,
-      labelTextBuilder: (position) {
-        final index =
-            min((position * itemCount).floor(), _collatedFiles.length - 1);
-        return Text(
-          getMonthAndYear(DateTime.fromMicrosecondsSinceEpoch(
-              _collatedFiles[index][0].creationTime)),
-          style: TextStyle(
-            color: Colors.black,
-            backgroundColor: Colors.white,
-            fontSize: 14,
-          ),
-        );
-      },
-      labelConstraints: BoxConstraints.tightFor(width: 100.0, height: 36.0),
-      onChange: (position) {
-        final index =
-            min((position * itemCount).floor(), _collatedFiles.length - 1);
-        if (index == _lastIndex) {
-          return;
-        }
-        _lastIndex = index;
-        _itemScrollController.jumpTo(index: index);
-      },
-      child: ScrollablePositionedList.builder(
-        itemCount: itemCount,
-        itemBuilder: _buildListItem,
-        itemScrollController: _itemScrollController,
+    } else {
+      gallery = DraggableScrollbar.semicircle(
+        key: _scrollKey,
         initialScrollIndex: _lastIndex,
-        minCacheExtent: 1500,
-        addAutomaticKeepAlives: true,
-        physics: _MaxVelocityPhysics(velocityThreshold: 128),
-        itemPositionsListener: _itemPositionsListener,
-      ),
-      itemCount: itemCount,
-    );
+        labelTextBuilder: (position) {
+          final index =
+              min((position * itemCount).floor(), _collatedFiles.length - 1);
+          return Text(
+            getMonthAndYear(DateTime.fromMicrosecondsSinceEpoch(
+                _collatedFiles[index][0].creationTime)),
+            style: TextStyle(
+              color: Colors.black,
+              backgroundColor: Colors.white,
+              fontSize: 14,
+            ),
+          );
+        },
+        labelConstraints: BoxConstraints.tightFor(width: 100.0, height: 36.0),
+        onChange: (position) {
+          final index =
+              min((position * itemCount).floor(), _collatedFiles.length - 1);
+          if (index == _lastIndex) {
+            return;
+          }
+          _lastIndex = index;
+          _itemScrollController.jumpTo(index: index);
+        },
+        child: ScrollablePositionedList.builder(
+          itemCount: itemCount,
+          itemBuilder: _buildListItem,
+          itemScrollController: _itemScrollController,
+          initialScrollIndex: _lastIndex,
+          minCacheExtent: 1500,
+          addAutomaticKeepAlives: true,
+          physics: _MaxVelocityPhysics(velocityThreshold: 128),
+          itemPositionsListener: _itemPositionsListener,
+        ),
+        itemCount: itemCount,
+      );
+    }
     if (widget.isHomePageGallery) {
       gallery = Container(
         margin: const EdgeInsets.only(bottom: 50),

+ 11 - 9
lib/ui/home_widget.dart

@@ -54,6 +54,7 @@ class _HomeWidgetState extends State<HomeWidget> {
   final PageController _pageController = PageController();
   final _future = FileRepository.instance.loadFiles();
   int _selectedTabIndex = 0;
+  Widget _headerWidgetWithSettingsButton;
 
   StreamSubscription<LocalPhotosUpdatedEvent> _photosUpdatedEvent;
   StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
@@ -66,6 +67,15 @@ class _HomeWidgetState extends State<HomeWidget> {
   @override
   void initState() {
     _logger.info("Building initstate");
+    _headerWidgetWithSettingsButton = Container(
+      margin: const EdgeInsets.only(top: 12),
+      child: Stack(
+        children: [
+          _headerWidget,
+          _settingsButton,
+        ],
+      ),
+    );
     _photosUpdatedEvent =
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
       _logger.info("Building because local photos updated");
@@ -226,15 +236,7 @@ class _HomeWidgetState extends State<HomeWidget> {
         if (snapshot.hasData) {
           var header;
           if (_selectedFiles.files.isEmpty) {
-            header = Container(
-              margin: EdgeInsets.only(top: 12),
-              child: Stack(
-                children: [
-                  _headerWidget,
-                  _settingsButton,
-                ],
-              ),
-            );
+            header = _headerWidgetWithSettingsButton;
           } else {
             header = _headerWidget;
           }