From fd676e0ac4715d244955482bc6f4237fdc34d8b3 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Wed, 7 Sep 2022 17:30:23 +0800 Subject: [PATCH] Simplify code --- app/lib/widget/album_browser.dart | 201 ++++++++-------------- app/lib/widget/dynamic_album_browser.dart | 62 +++---- app/lib/widget/smart_album_browser.dart | 63 +++---- 3 files changed, 117 insertions(+), 209 deletions(-) diff --git a/app/lib/widget/album_browser.dart b/app/lib/widget/album_browser.dart index 45a542a9..4f1a6a1c 100644 --- a/app/lib/widget/album_browser.dart +++ b/app/lib/widget/album_browser.dart @@ -903,14 +903,11 @@ abstract class _ListItem implements SelectableItem, DraggableItem { const _ListItem({ required this.index, this.onTap, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : _onDropBefore = onDropBefore, - _onDropAfter = onDropAfter, - _onDragStarted = onDragStarted, - _onDragEndedAny = onDragEndedAny; + this.onDropBefore, + this.onDropAfter, + this.onDragStarted, + this.onDragEndedAny, + }); @override get isTappable => onTap != null; @@ -921,18 +918,6 @@ abstract class _ListItem implements SelectableItem, DraggableItem { @override get isDraggable => true; - @override - get onDropBefore => _onDropBefore; - - @override - get onDropAfter => _onDropAfter; - - @override - get onDragStarted => _onDragStarted; - - @override - get onDragEndedAny => _onDragEndedAny; - @override get staggeredTile => const StaggeredTile.count(1, 1); @@ -940,71 +925,56 @@ abstract class _ListItem implements SelectableItem, DraggableItem { buildDragFeedbackWidget(BuildContext context) => null; @override - toString() { - return "$runtimeType {" - "index: $index, " - "}"; - } + toString() => "$runtimeType {" + "index: $index, " + "}"; final int index; final VoidCallback? onTap; - final DragTargetAccept? _onDropBefore; - final DragTargetAccept? _onDropAfter; - final VoidCallback? _onDragStarted; - final VoidCallback? _onDragEndedAny; + @override + final DragTargetAccept? onDropBefore; + @override + final DragTargetAccept? onDropAfter; + @override + final VoidCallback? onDragStarted; + @override + final VoidCallback? onDragEndedAny; } abstract class _FileListItem extends _ListItem { _FileListItem({ - required int index, + required super.index, required this.file, - VoidCallback? onTap, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : super( - index: index, - onTap: onTap, - onDropBefore: onDropBefore, - onDropAfter: onDropAfter, - onDragStarted: onDragStarted, - onDragEndedAny: onDragEndedAny, - ); + super.onTap, + super.onDropBefore, + super.onDropAfter, + super.onDragStarted, + super.onDragEndedAny, + }); final File file; } class _ImageListItem extends _FileListItem { _ImageListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : super( - index: index, - file: file, - onTap: onTap, - onDropBefore: onDropBefore, - onDropAfter: onDropAfter, - onDragStarted: onDragStarted, - onDragEndedAny: onDragEndedAny, - ); + super.onTap, + super.onDropBefore, + super.onDropAfter, + super.onDragStarted, + super.onDragEndedAny, + }); @override - buildWidget(BuildContext context) { - return PhotoListImage( - account: account, - previewUrl: previewUrl, - isGif: file.contentType == "image/gif", - ); - } + buildWidget(BuildContext context) => PhotoListImage( + account: account, + previewUrl: previewUrl, + isGif: file.contentType == "image/gif", + ); final Account account; final String previewUrl; @@ -1012,32 +982,22 @@ class _ImageListItem extends _FileListItem { class _VideoListItem extends _FileListItem { _VideoListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : super( - index: index, - file: file, - onTap: onTap, - onDropBefore: onDropBefore, - onDropAfter: onDropAfter, - onDragStarted: onDragStarted, - onDragEndedAny: onDragEndedAny, - ); + super.onTap, + super.onDropBefore, + super.onDropAfter, + super.onDragStarted, + super.onDragEndedAny, + }); @override - buildWidget(BuildContext context) { - return PhotoListVideo( - account: account, - previewUrl: previewUrl, - ); - } + buildWidget(BuildContext context) => PhotoListVideo( + account: account, + previewUrl: previewUrl, + ); final Account account; final String previewUrl; @@ -1045,58 +1005,41 @@ class _VideoListItem extends _FileListItem { class _LabelListItem extends _ListItem { _LabelListItem({ - required int index, + required super.index, required this.text, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : super( - index: index, - onDropBefore: onDropBefore, - onDropAfter: onDropAfter, - onDragStarted: onDragStarted, - onDragEndedAny: onDragEndedAny, - ); + super.onDropBefore, + super.onDropAfter, + super.onDragStarted, + super.onDragEndedAny, + }); @override get staggeredTile => const StaggeredTile.extent(99, 56); @override - buildWidget(BuildContext context) { - return PhotoListLabel( - text: text, - ); - } + buildWidget(BuildContext context) => PhotoListLabel( + text: text, + ); final String text; } class _EditLabelListItem extends _LabelListItem { _EditLabelListItem({ - required int index, - required String text, + required super.index, + required super.text, required this.onEditPressed, - DragTargetAccept? onDropBefore, - DragTargetAccept? onDropAfter, - VoidCallback? onDragStarted, - VoidCallback? onDragEndedAny, - }) : super( - index: index, - text: text, - onDropBefore: onDropBefore, - onDropAfter: onDropAfter, - onDragStarted: onDragStarted, - onDragEndedAny: onDragEndedAny, - ); + super.onDropBefore, + super.onDropAfter, + super.onDragStarted, + super.onDragEndedAny, + }); @override - buildWidget(BuildContext context) { - return PhotoListLabelEdit( - text: text, - onEditPressed: onEditPressed, - ); - } + buildWidget(BuildContext context) => PhotoListLabelEdit( + text: text, + onEditPressed: onEditPressed, + ); @override buildDragFeedbackWidget(BuildContext context) { @@ -1118,11 +1061,9 @@ class _DateListItem extends _ListItem { get staggeredTile => const StaggeredTile.extent(99, 32); @override - buildWidget(BuildContext context) { - return PhotoListDate( - date: date, - ); - } + buildWidget(BuildContext context) => PhotoListDate( + date: date, + ); final DateTime date; } diff --git a/app/lib/widget/dynamic_album_browser.dart b/app/lib/widget/dynamic_album_browser.dart index 3f0af7c8..fc44d892 100644 --- a/app/lib/widget/dynamic_album_browser.dart +++ b/app/lib/widget/dynamic_album_browser.dart @@ -680,11 +680,9 @@ abstract class _ListItem implements SelectableItem { get staggeredTile => const StaggeredTile.count(1, 1); @override - toString() { - return "$runtimeType {" - "index: $index, " - "}"; - } + toString() => "$runtimeType {" + "index: $index, " + "}"; final int index; @@ -706,25 +704,19 @@ abstract class _FileListItem extends _ListItem { class _ImageListItem extends _FileListItem { _ImageListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - }) : super( - index: index, - file: file, - onTap: onTap, - ); + super.onTap, + }); @override - buildWidget(BuildContext context) { - return PhotoListImage( - account: account, - previewUrl: previewUrl, - isGif: file.contentType == "image/gif", - ); - } + buildWidget(BuildContext context) => PhotoListImage( + account: account, + previewUrl: previewUrl, + isGif: file.contentType == "image/gif", + ); final Account account; final String previewUrl; @@ -732,24 +724,18 @@ class _ImageListItem extends _FileListItem { class _VideoListItem extends _FileListItem { _VideoListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - }) : super( - index: index, - file: file, - onTap: onTap, - ); + super.onTap, + }); @override - buildWidget(BuildContext context) { - return PhotoListVideo( - account: account, - previewUrl: previewUrl, - ); - } + buildWidget(BuildContext context) => PhotoListVideo( + account: account, + previewUrl: previewUrl, + ); final Account account; final String previewUrl; @@ -767,11 +753,9 @@ class _DateListItem extends _ListItem { get staggeredTile => const StaggeredTile.extent(99, 32); @override - buildWidget(BuildContext context) { - return PhotoListDate( - date: date, - ); - } + buildWidget(BuildContext context) => PhotoListDate( + date: date, + ); final DateTime date; } diff --git a/app/lib/widget/smart_album_browser.dart b/app/lib/widget/smart_album_browser.dart index 8b0937e6..57e4375d 100644 --- a/app/lib/widget/smart_album_browser.dart +++ b/app/lib/widget/smart_album_browser.dart @@ -352,11 +352,9 @@ abstract class _ListItem implements SelectableItem { get staggeredTile => const StaggeredTile.count(1, 1); @override - toString() { - return "$runtimeType {" - "index: $index, " - "}"; - } + toString() => "$runtimeType {" + "index: $index, " + "}"; final int index; @@ -365,38 +363,29 @@ abstract class _ListItem implements SelectableItem { abstract class _FileListItem extends _ListItem { _FileListItem({ - required int index, + required super.index, required this.file, - VoidCallback? onTap, - }) : super( - index: index, - onTap: onTap, - ); + super.onTap, + }); final File file; } class _ImageListItem extends _FileListItem { _ImageListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - }) : super( - index: index, - file: file, - onTap: onTap, - ); + super.onTap, + }); @override - buildWidget(BuildContext context) { - return PhotoListImage( - account: account, - previewUrl: previewUrl, - isGif: file.contentType == "image/gif", - ); - } + buildWidget(BuildContext context) => PhotoListImage( + account: account, + previewUrl: previewUrl, + isGif: file.contentType == "image/gif", + ); final Account account; final String previewUrl; @@ -404,24 +393,18 @@ class _ImageListItem extends _FileListItem { class _VideoListItem extends _FileListItem { _VideoListItem({ - required int index, - required File file, + required super.index, + required super.file, required this.account, required this.previewUrl, - VoidCallback? onTap, - }) : super( - index: index, - file: file, - onTap: onTap, - ); + super.onTap, + }); @override - buildWidget(BuildContext context) { - return PhotoListVideo( - account: account, - previewUrl: previewUrl, - ); - } + buildWidget(BuildContext context) => PhotoListVideo( + account: account, + previewUrl: previewUrl, + ); final Account account; final String previewUrl;