From 06e8e60efabf9e55fc918584823da9e3171a5862 Mon Sep 17 00:00:00 2001 From: Vishnu Mohandas Date: Sat, 6 Feb 2021 01:10:55 +0530 Subject: [PATCH] Fix appbar issue with mail gallery --- lib/ui/gallery.dart | 24 ++++++++++++++++++++++-- lib/ui/home_widget.dart | 19 +++++-------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/ui/gallery.dart b/lib/ui/gallery.dart index 49538824f..33ea4f4bb 100644 --- a/lib/ui/gallery.dart +++ b/lib/ui/gallery.dart @@ -11,6 +11,7 @@ import 'package:photos/models/selected_files.dart'; import 'package:photos/ui/common_elements.dart'; import 'package:photos/ui/detail_page.dart'; import 'package:photos/ui/draggable_scrollbar.dart'; +import 'package:photos/ui/gallery_app_bar_widget.dart'; import 'package:photos/ui/loading_widget.dart'; import 'package:photos/ui/thumbnail_widget.dart'; import 'package:photos/utils/date_time_util.dart'; @@ -24,6 +25,7 @@ class Gallery extends StatefulWidget { final SelectedFiles selectedFiles; final String tagPrefix; final Widget headerWidget; + final bool isHomePageGallery; Gallery({ this.syncLoader, @@ -33,6 +35,7 @@ class Gallery extends StatefulWidget { this.headerWidget, @required this.selectedFiles, @required this.tagPrefix, + this.isHomePageGallery, }); @override @@ -145,17 +148,19 @@ class _GalleryState extends State { final itemCount = _collatedFiles.length + (widget.headerWidget == null ? 1 : 2); _hasDraggableScrollbar = itemCount > 25 || _files.length > 50; + var gallery; if (!_hasDraggableScrollbar) { _scrollController = ScrollController(initialScrollOffset: _scrollOffset); - return ListView.builder( + gallery = ListView.builder( itemCount: itemCount, itemBuilder: _buildListItem, controller: _scrollController, cacheExtent: 1500, addAutomaticKeepAlives: true, ); + return gallery; } - return DraggableScrollbar.semicircle( + gallery = DraggableScrollbar.semicircle( key: _scrollKey, initialScrollIndex: _lastIndex, labelTextBuilder: (position) { @@ -193,6 +198,21 @@ class _GalleryState extends State { ), itemCount: itemCount, ); + if (widget.selectedFiles.files.isNotEmpty && widget.isHomePageGallery) { + return Stack(children: [ + gallery, + Container( + height: 60, + child: GalleryAppBarWidget( + GalleryAppBarType.homepage, + null, + widget.selectedFiles, + ), + ), + ]); + } else { + return gallery; + } } Widget _buildListItem(BuildContext context, int index) { diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index c32797671..f171866b1 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -74,10 +74,6 @@ class _HomeWidgetState extends State { ); } }); - _selectedFiles.addListener(() { - _logger.info("Building because selected files updated"); - setState(() {}); - }); _initDeepLinks(); super.initState(); } @@ -86,16 +82,10 @@ class _HomeWidgetState extends State { Widget build(BuildContext context) { _logger.info("Building home_Widget"); return Scaffold( - appBar: _selectedFiles.files.isEmpty - ? PreferredSize( - preferredSize: Size.fromHeight(0), - child: Container(), - ) - : GalleryAppBarWidget( - GalleryAppBarType.homepage, - widget.title, - _selectedFiles, - ), + appBar: PreferredSize( + preferredSize: Size.fromHeight(0), + child: Container(), + ), bottomNavigationBar: _buildBottomNavigationBar(), body: ExtentsPageView( children: [ @@ -178,6 +168,7 @@ class _HomeWidgetState extends State { tagPrefix: "home_gallery", selectedFiles: _selectedFiles, headerWidget: header, + isHomePageGallery: true, ); } else if (snapshot.hasError) { return Center(child: Text(snapshot.error.toString()));