mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Refactoring
This commit is contained in:
parent
8d73bf2f84
commit
cf8f696738
6 changed files with 27 additions and 37 deletions
|
@ -156,7 +156,9 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
ignoring: isEditMode,
|
||||
sliver: SliverOpacity(
|
||||
opacity: isEditMode ? .25 : 1,
|
||||
sliver: buildItemStreamList(context),
|
||||
sliver: buildItemStreamList(
|
||||
maxCrossAxisExtent: thumbSize.toDouble(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -179,9 +179,6 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
get itemStreamListCellSize => thumbSize;
|
||||
|
||||
@protected
|
||||
get isEditMode => _isEditMode;
|
||||
|
||||
|
|
|
@ -73,9 +73,6 @@ class _ArchiveViewerState extends State<ArchiveViewer>
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
get itemStreamListCellSize => _thumbSize;
|
||||
|
||||
void _initBloc() {
|
||||
_bloc = ScanDirBloc.of(widget.account);
|
||||
if (_bloc.state is ScanDirBlocInit) {
|
||||
|
@ -105,7 +102,9 @@ class _ArchiveViewerState extends State<ArchiveViewer>
|
|||
_buildAppBar(context),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: buildItemStreamList(context),
|
||||
sliver: buildItemStreamList(
|
||||
maxCrossAxisExtent: _thumbSize.toDouble(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -180,7 +180,9 @@ class _DynamicAlbumViewerState extends State<DynamicAlbumViewer>
|
|||
ignoring: isEditMode,
|
||||
sliver: SliverOpacity(
|
||||
opacity: isEditMode ? .25 : 1,
|
||||
sliver: buildItemStreamList(context),
|
||||
sliver: buildItemStreamList(
|
||||
maxCrossAxisExtent: thumbSize.toDouble(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -69,14 +69,6 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onMaxExtentChanged(double maxExtent) {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
int get itemStreamListCellSize => _thumbSize;
|
||||
|
||||
void _initBloc() {
|
||||
_bloc = ScanDirBloc.of(widget.account);
|
||||
if (_bloc.state is ScanDirBlocInit) {
|
||||
|
@ -115,7 +107,14 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
_buildAppBar(context),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
sliver: buildItemStreamList(context),
|
||||
sliver: buildItemStreamList(
|
||||
maxCrossAxisExtent: _thumbSize.toDouble(),
|
||||
onMaxExtentChanged: (value) {
|
||||
setState(() {
|
||||
_itemListMaxExtent = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -517,14 +516,14 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
|
||||
/// Return the estimated scroll extent of the custom scroll view, or null
|
||||
double _getScrollViewExtent(BoxConstraints constraints) {
|
||||
if (calculatedMaxExtent != null &&
|
||||
if (_itemListMaxExtent != null &&
|
||||
constraints.hasBoundedHeight &&
|
||||
_appBarExtent != null) {
|
||||
// scroll extent = list height - widget viewport height + sliver app bar height
|
||||
final scrollExtent =
|
||||
calculatedMaxExtent - constraints.maxHeight + _appBarExtent;
|
||||
_itemListMaxExtent - constraints.maxHeight + _appBarExtent;
|
||||
_log.info(
|
||||
"[_getScrollViewExtent] $calculatedMaxExtent - ${constraints.maxHeight} + $_appBarExtent = $scrollExtent");
|
||||
"[_getScrollViewExtent] $_itemListMaxExtent - ${constraints.maxHeight} + $_appBarExtent = $scrollExtent");
|
||||
return scrollExtent;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -574,6 +573,7 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
double _appBarExtent;
|
||||
double _itemListMaxExtent;
|
||||
|
||||
static final _log = Logger("widget.home_photos._HomePhotosState");
|
||||
static const _menuValueRefresh = 0;
|
||||
|
|
|
@ -55,23 +55,20 @@ mixin SelectableItemStreamListMixin<T extends StatefulWidget> on State<T> {
|
|||
}
|
||||
|
||||
@protected
|
||||
Widget buildItemStreamList(BuildContext context) {
|
||||
Widget buildItemStreamList({
|
||||
@required double maxCrossAxisExtent,
|
||||
ValueChanged<double> onMaxExtentChanged,
|
||||
}) {
|
||||
return MeasurableItemList(
|
||||
key: _listKey,
|
||||
maxCrossAxisExtent: itemStreamListCellSize.toDouble(),
|
||||
maxCrossAxisExtent: maxCrossAxisExtent,
|
||||
itemCount: _items.length,
|
||||
itemBuilder: _buildItem,
|
||||
staggeredTileBuilder: (index) => _items[index].staggeredTile,
|
||||
onMaxExtentChanged: (newExtent) {
|
||||
_calculatedMaxExtent = newExtent;
|
||||
onMaxExtentChanged(newExtent);
|
||||
},
|
||||
onMaxExtentChanged: onMaxExtentChanged,
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
void onMaxExtentChanged(double newExtent) {}
|
||||
|
||||
@protected
|
||||
void clearSelectedItems() {
|
||||
_selectedItems.clear();
|
||||
|
@ -113,12 +110,6 @@ mixin SelectableItemStreamListMixin<T extends StatefulWidget> on State<T> {
|
|||
(_listKey.currentState as MeasurableItemListState)?.updateListHeight());
|
||||
}
|
||||
|
||||
@protected
|
||||
int get itemStreamListCellSize;
|
||||
|
||||
@protected
|
||||
double get calculatedMaxExtent => _calculatedMaxExtent;
|
||||
|
||||
Widget _buildItem(BuildContext context, int index) {
|
||||
final item = _items[index];
|
||||
final content = Padding(
|
||||
|
@ -237,7 +228,6 @@ mixin SelectableItemStreamListMixin<T extends StatefulWidget> on State<T> {
|
|||
final _selectedItems = <SelectableItemStreamListItem>{};
|
||||
|
||||
final _listKey = GlobalKey();
|
||||
double _calculatedMaxExtent;
|
||||
|
||||
/// used to gain focus on web for keyboard support
|
||||
final _keyboardFocus = FocusNode();
|
||||
|
|
Loading…
Reference in a new issue