chore: Made poster image stateless

This commit is contained in:
PartyDonut 2025-10-11 18:55:05 +02:00
parent 117d873683
commit be2bad14f1

View file

@ -22,7 +22,7 @@ import 'package:fladder/widgets/shared/item_actions.dart';
import 'package:fladder/widgets/shared/modal_bottom_sheet.dart'; import 'package:fladder/widgets/shared/modal_bottom_sheet.dart';
import 'package:fladder/widgets/shared/status_card.dart'; import 'package:fladder/widgets/shared/status_card.dart';
class PosterImage extends ConsumerStatefulWidget { class PosterImage extends ConsumerWidget {
final ItemBaseModel poster; final ItemBaseModel poster;
final bool? selected; final bool? selected;
final ValueChanged<bool>? playVideo; final ValueChanged<bool>? playVideo;
@ -53,56 +53,43 @@ class PosterImage extends ConsumerStatefulWidget {
}); });
@override @override
ConsumerState<ConsumerStatefulWidget> createState() => _PosterImageState(); Widget build(BuildContext context, WidgetRef ref) {
} final posterRadius = FladderTheme.smallShape.borderRadius;
class _PosterImageState extends ConsumerState<PosterImage> {
final tag = UniqueKey();
void pressedWidget(BuildContext context) async {
if (widget.onPressed != null) {
widget.onPressed?.call(() async {
await navigateToDetails();
context.refreshData();
}, widget.poster);
} else {
await navigateToDetails();
if (!context.mounted) return;
context.refreshData();
}
}
Future<void> navigateToDetails() async {
await widget.poster.navigateTo(context, ref: ref, tag: tag);
}
final posterRadius = FladderTheme.smallShape.borderRadius;
@override
Widget build(BuildContext context) {
final poster = widget.poster;
final padding = const EdgeInsets.all(5); final padding = const EdgeInsets.all(5);
final myKey = key ?? UniqueKey();
return Hero( return Hero(
tag: tag, tag: myKey,
child: FocusButton( child: FocusButton(
onTap: () => pressedWidget(context), onTap: () async {
onFocusChanged: widget.onFocusChanged, if (onPressed != null) {
onPressed?.call(() async {
await poster.navigateTo(context, ref: ref, tag: myKey);
context.refreshData();
}, poster);
} else {
await poster.navigateTo(context, ref: ref, tag: myKey);
if (!context.mounted) return;
context.refreshData();
}
},
onFocusChanged: onFocusChanged,
onLongPress: () { onLongPress: () {
showBottomSheetPill( showBottomSheetPill(
context: context, context: context,
item: widget.poster, item: poster,
content: (scrollContext, scrollController) => ListView( content: (scrollContext, scrollController) => ListView(
shrinkWrap: true, shrinkWrap: true,
controller: scrollController, controller: scrollController,
children: widget.poster children: poster
.generateActions( .generateActions(
context, context,
ref, ref,
exclude: widget.excludeActions, exclude: excludeActions,
otherActions: widget.otherActions, otherActions: otherActions,
onUserDataChanged: widget.onUserDataChanged, onUserDataChanged: onUserDataChanged,
onDeleteSuccesFully: widget.onItemRemoved, onDeleteSuccesFully: onItemRemoved,
onItemUpdated: widget.onItemUpdated, onItemUpdated: onItemUpdated,
) )
.listTileItems(scrollContext, useIcons: true), .listTileItems(scrollContext, useIcons: true),
), ),
@ -115,15 +102,15 @@ class _PosterImageState extends ConsumerState<PosterImage> {
await showMenu( await showMenu(
context: context, context: context,
position: position, position: position,
items: widget.poster items: poster
.generateActions( .generateActions(
context, context,
ref, ref,
exclude: widget.excludeActions, exclude: excludeActions,
otherActions: widget.otherActions, otherActions: otherActions,
onUserDataChanged: widget.onUserDataChanged, onUserDataChanged: onUserDataChanged,
onDeleteSuccesFully: widget.onItemRemoved, onDeleteSuccesFully: onItemRemoved,
onItemUpdated: widget.onItemUpdated, onItemUpdated: onItemUpdated,
) )
.popupMenuItems(useIcons: true), .popupMenuItems(useIcons: true),
); );
@ -142,12 +129,12 @@ class _PosterImageState extends ConsumerState<PosterImage> {
fit: StackFit.expand, fit: StackFit.expand,
children: [ children: [
FladderImage( FladderImage(
image: widget.primaryPosters image: primaryPosters
? widget.poster.images?.primary ? poster.images?.primary
: widget.poster.getPosters?.primary ?? widget.poster.getPosters?.backDrop?.lastOrNull, : poster.getPosters?.primary ?? poster.getPosters?.backDrop?.lastOrNull,
placeHolder: PosterPlaceholder(item: widget.poster), placeHolder: PosterPlaceholder(item: poster),
), ),
if (poster.userData.progress > 0 && widget.poster.type == FladderItemType.book) if (poster.userData.progress > 0 && poster.type == FladderItemType.book)
Align( Align(
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: Padding( child: Padding(
@ -156,7 +143,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(5.5), padding: const EdgeInsets.all(5.5),
child: Text( child: Text(
context.localized.page((widget.poster as BookModel).currentPage), context.localized.page((poster as BookModel).currentPage),
style: Theme.of(context).textTheme.labelLarge?.copyWith( style: Theme.of(context).textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
@ -167,7 +154,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
), ),
), ),
), ),
if (widget.selected == true) if (selected == true)
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.15), color: Colors.black.withValues(alpha: 0.15),
@ -184,7 +171,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(2), padding: const EdgeInsets.all(2),
child: Text( child: Text(
widget.poster.name, poster.name,
maxLines: 2, maxLines: 2,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: Theme.of(context) style: Theme.of(context)
@ -202,7 +189,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (widget.poster.userData.isFavourite) if (poster.userData.isFavourite)
const Row( const Row(
children: [ children: [
StatusCard( StatusCard(
@ -216,7 +203,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
], ],
), ),
if ((poster.userData.progress > 0 && poster.userData.progress < 100) && if ((poster.userData.progress > 0 && poster.userData.progress < 100) &&
widget.poster.type != FladderItemType.book) ...{ poster.type != FladderItemType.book) ...{
const SizedBox( const SizedBox(
height: 4, height: 4,
), ),
@ -238,33 +225,33 @@ class _PosterImageState extends ConsumerState<PosterImage> {
], ],
), ),
), ),
if (widget.inlineTitle) if (inlineTitle)
Align( Align(
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
child: Text( child: Text(
widget.poster.title.maxLength(limitTo: 25), poster.title.maxLength(limitTo: 25),
style: style:
Theme.of(context).textTheme.labelLarge?.copyWith(fontSize: 20, fontWeight: FontWeight.bold), Theme.of(context).textTheme.labelLarge?.copyWith(fontSize: 20, fontWeight: FontWeight.bold),
), ),
), ),
), ),
if ((widget.poster.unPlayedItemCount != null && widget.poster is SeriesModel) || if ((poster.unPlayedItemCount != null && poster is SeriesModel) ||
(widget.poster.playAble && !widget.poster.unWatched && widget.poster is! PhotoAlbumModel)) (poster.playAble && !poster.unWatched && poster is! PhotoAlbumModel))
IgnorePointer( IgnorePointer(
child: Align( child: Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: StatusCard( child: StatusCard(
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
useFittedBox: widget.poster.unPlayedItemCount != 0, useFittedBox: poster.unPlayedItemCount != 0,
child: Padding( child: Padding(
padding: const EdgeInsets.all(6), padding: const EdgeInsets.all(6),
child: widget.poster.unPlayedItemCount != 0 child: poster.unPlayedItemCount != 0
? Container( ? Container(
constraints: const BoxConstraints(minWidth: 16), constraints: const BoxConstraints(minWidth: 16),
child: Text( child: Text(
widget.poster.userData.unPlayedItemCount.toString(), poster.userData.unPlayedItemCount.toString(),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
@ -283,9 +270,8 @@ class _PosterImageState extends ConsumerState<PosterImage> {
), ),
), ),
), ),
if (widget.poster.overview.runTime != null && if (poster.overview.runTime != null &&
((widget.poster is PhotoModel) && ((poster is PhotoModel) && (poster as PhotoModel).internalType == FladderItemType.video)) ...{
(widget.poster as PhotoModel).internalType == FladderItemType.video)) ...{
Align( Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: Padding( child: Padding(
@ -299,7 +285,7 @@ class _PosterImageState extends ConsumerState<PosterImage> {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Text( Text(
widget.poster.overview.runTime.humanizeSmall ?? "", poster.overview.runTime.humanizeSmall ?? "",
style: Theme.of(context).textTheme.bodyLarge?.copyWith( style: Theme.of(context).textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
@ -324,11 +310,11 @@ class _PosterImageState extends ConsumerState<PosterImage> {
//Poster Button //Poster Button
if (AdaptiveLayout.inputDeviceOf(context) == InputDevice.pointer) ...[ if (AdaptiveLayout.inputDeviceOf(context) == InputDevice.pointer) ...[
// Play Button // Play Button
if (widget.poster.playAble) if (poster.playAble)
Align( Align(
alignment: Alignment.center, alignment: Alignment.center,
child: IconButton.filledTonal( child: IconButton.filledTonal(
onPressed: () => widget.playVideo?.call(false), onPressed: () => playVideo?.call(false),
icon: const Icon( icon: const Icon(
IconsaxPlusBold.play, IconsaxPlusBold.play,
size: 32, size: 32,
@ -341,20 +327,20 @@ class _PosterImageState extends ConsumerState<PosterImage> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
PopupMenuButton( PopupMenuButton(
tooltip: "Options", tooltip: context.localized.options,
icon: const Icon( icon: const Icon(
Icons.more_vert, Icons.more_vert,
color: Colors.white, color: Colors.white,
), ),
itemBuilder: (context) => widget.poster itemBuilder: (context) => poster
.generateActions( .generateActions(
context, context,
ref, ref,
exclude: widget.excludeActions, exclude: excludeActions,
otherActions: widget.otherActions, otherActions: otherActions,
onUserDataChanged: widget.onUserDataChanged, onUserDataChanged: onUserDataChanged,
onDeleteSuccesFully: widget.onItemRemoved, onDeleteSuccesFully: onItemRemoved,
onItemUpdated: widget.onItemUpdated, onItemUpdated: onItemUpdated,
) )
.popupMenuItems(useIcons: true), .popupMenuItems(useIcons: true),
), ),