From 39cc9b8d7c2e2815e4fb787eaf033a0e57b072f7 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 26 Jul 2026 18:55:42 +0200 Subject: [PATCH] feat: Fix framework assertion when adding an item --- lib/main.dart | 8 ++- lib/src/ui/widgets/image.dart | 86 +++++++++++++++++-------------- lib/src/ui/widgets/list_item.dart | 2 - 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 7f0dc1d..25c9edd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -122,9 +122,13 @@ class MyApp extends StatelessWidget { if (state is NoopNavigationState) { // NOOP } else if (state is PushNavigationState) { - _router.go(state.destination); - } else if (state is GoNavigationState) { _router.push(state.destination); + } else if (state is GoNavigationState) { + if (_router.canPop()) { + _router.replace(state.destination); + } else { + _router.go(state.destination); + } } else if (state is PoppedNavigationState) { _router.pop(); } diff --git a/lib/src/ui/widgets/image.dart b/lib/src/ui/widgets/image.dart index c364858..21527f2 100644 --- a/lib/src/ui/widgets/image.dart +++ b/lib/src/ui/widgets/image.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; class AnimeCoverImage extends StatelessWidget { const AnimeCoverImage({ required this.url, - required this.hero, + this.hero, this.cached = true, this.extra, this.onTap, @@ -18,7 +18,7 @@ class AnimeCoverImage extends StatelessWidget { final bool cached; /// The hero tag of the image. - final String hero; + final String? hero; /// An extra widget with a translucent backdrop. final Widget? extra; @@ -28,53 +28,59 @@ class AnimeCoverImage extends StatelessWidget { @override Widget build(BuildContext context) { - return Hero( - tag: hero, - child: ClipRRect( - borderRadius: BorderRadius.circular(8), - child: Material( - child: SizedBox( - height: 100 * (16 / 9), - width: 120, - child: InkWell( - onTap: onTap ?? () {}, - child: Stack( - children: [ - Positioned( - left: 0, - right: 0, - top: 0, - bottom: 0, - child: DecoratedBox( - decoration: BoxDecoration( - image: DecorationImage( - image: cached - ? CachedNetworkImageProvider(url) as ImageProvider - : NetworkImage(url), - fit: BoxFit.cover, - ), + final image = ClipRRect( + borderRadius: BorderRadius.circular(8), + child: Material( + child: SizedBox( + height: 100 * (16 / 9), + width: 120, + child: InkWell( + onTap: onTap ?? () {}, + child: Stack( + children: [ + Positioned( + left: 0, + right: 0, + top: 0, + bottom: 0, + child: DecoratedBox( + decoration: BoxDecoration( + image: DecorationImage( + image: cached + ? CachedNetworkImageProvider(url) as ImageProvider + : NetworkImage(url), + fit: BoxFit.cover, ), ), ), - if (extra != null) - Positioned( - left: 0, - bottom: 0, - right: 0, - child: SizedBox( - height: 40, - child: ColoredBox( - color: Colors.black54, - child: extra, - ), + ), + if (extra != null) + Positioned( + left: 0, + bottom: 0, + right: 0, + child: SizedBox( + height: 40, + child: ColoredBox( + color: Colors.black54, + child: extra, ), ), - ], - ), + ), + ], ), ), ), ), ); + + if (hero != null) { + return Hero( + tag: hero!, + child: image, + ); + } + + return image; } } diff --git a/lib/src/ui/widgets/list_item.dart b/lib/src/ui/widgets/list_item.dart index ae9addf..7d4f276 100644 --- a/lib/src/ui/widgets/list_item.dart +++ b/lib/src/ui/widgets/list_item.dart @@ -76,8 +76,6 @@ class ListItem extends StatelessWidget { children: [ AnimeCoverImage( cached: cached, - // TODO(Unknown): Have the ID here - hero: thumbnailUrl, extra: imageExtra, url: thumbnailUrl, ),