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