From b240870ebfa5e48d26b095a4758a64078d94675f Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Mon, 6 Feb 2023 20:09:26 +0100 Subject: [PATCH] fix(ui): Fix title overflow in details view --- lib/src/data/anime.dart | 2 +- lib/src/data/manga.dart | 2 +- lib/src/data/type.dart | 12 ++++++ lib/src/ui/bloc/details_bloc.freezed.dart | 16 ++++---- lib/src/ui/bloc/details_state.dart | 2 +- lib/src/ui/pages/details.dart | 46 +++++++++++------------ 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/lib/src/data/anime.dart b/lib/src/data/anime.dart index 2203924..0b86ff0 100644 --- a/lib/src/data/anime.dart +++ b/lib/src/data/anime.dart @@ -6,7 +6,7 @@ part 'anime.g.dart'; /// Data about a tracked anime @freezed -class AnimeTrackingData with _$AnimeTrackingData{ +class AnimeTrackingData with _$AnimeTrackingData, TrackingMedium { factory AnimeTrackingData( /// The ID of the anime String id, diff --git a/lib/src/data/manga.dart b/lib/src/data/manga.dart index ec66d59..cf28e9a 100644 --- a/lib/src/data/manga.dart +++ b/lib/src/data/manga.dart @@ -6,7 +6,7 @@ part 'manga.g.dart'; /// Data about a tracked anime @freezed -class MangaTrackingData with _$MangaTrackingData{ +class MangaTrackingData with _$MangaTrackingData, TrackingMedium { factory MangaTrackingData( /// The ID of the manga String id, diff --git a/lib/src/data/type.dart b/lib/src/data/type.dart index 209c0a8..fa7dcd2 100644 --- a/lib/src/data/type.dart +++ b/lib/src/data/type.dart @@ -15,6 +15,18 @@ enum MediumTrackingState { all, } +/// Interface for the Anime and Manga data classes +abstract class TrackingMedium { + /// The title of the medium + final String title = ''; + + /// The URL of the cover image. + final String thumbnailUrl = ''; + + /// The tracking state + final MediumTrackingState state = MediumTrackingState.planned; +} + extension MediumStateExtension on MediumTrackingState { int toInteger() { assert(this != MediumTrackingState.all, 'MediumTrackingState.all must not be serialized'); diff --git a/lib/src/ui/bloc/details_bloc.freezed.dart b/lib/src/ui/bloc/details_bloc.freezed.dart index 98d961d..34372e7 100644 --- a/lib/src/ui/bloc/details_bloc.freezed.dart +++ b/lib/src/ui/bloc/details_bloc.freezed.dart @@ -16,7 +16,7 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$DetailsState { - dynamic get data => throw _privateConstructorUsedError; + TrackingMedium? get data => throw _privateConstructorUsedError; TrackingMediumType get trackingType => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -29,7 +29,7 @@ abstract class $DetailsStateCopyWith<$Res> { factory $DetailsStateCopyWith( DetailsState value, $Res Function(DetailsState) then) = _$DetailsStateCopyWithImpl<$Res>; - $Res call({dynamic data, TrackingMediumType trackingType}); + $Res call({TrackingMedium? data, TrackingMediumType trackingType}); } /// @nodoc @@ -49,7 +49,7 @@ class _$DetailsStateCopyWithImpl<$Res> implements $DetailsStateCopyWith<$Res> { data: data == freezed ? _value.data : data // ignore: cast_nullable_to_non_nullable - as dynamic, + as TrackingMedium?, trackingType: trackingType == freezed ? _value.trackingType : trackingType // ignore: cast_nullable_to_non_nullable @@ -65,7 +65,7 @@ abstract class _$$_DetailsStateCopyWith<$Res> _$_DetailsState value, $Res Function(_$_DetailsState) then) = __$$_DetailsStateCopyWithImpl<$Res>; @override - $Res call({dynamic data, TrackingMediumType trackingType}); + $Res call({TrackingMedium? data, TrackingMediumType trackingType}); } /// @nodoc @@ -88,7 +88,7 @@ class __$$_DetailsStateCopyWithImpl<$Res> data: data == freezed ? _value.data : data // ignore: cast_nullable_to_non_nullable - as dynamic, + as TrackingMedium?, trackingType: trackingType == freezed ? _value.trackingType : trackingType // ignore: cast_nullable_to_non_nullable @@ -103,7 +103,7 @@ class _$_DetailsState implements _DetailsState { _$_DetailsState({this.data, this.trackingType = TrackingMediumType.anime}); @override - final dynamic data; + final TrackingMedium? data; @override @JsonKey() final TrackingMediumType trackingType; @@ -137,11 +137,11 @@ class _$_DetailsState implements _DetailsState { abstract class _DetailsState implements DetailsState { factory _DetailsState( - {final dynamic data, + {final TrackingMedium? data, final TrackingMediumType trackingType}) = _$_DetailsState; @override - dynamic get data; + TrackingMedium? get data; @override TrackingMediumType get trackingType; @override diff --git a/lib/src/ui/bloc/details_state.dart b/lib/src/ui/bloc/details_state.dart index c1af52c..01c95a2 100644 --- a/lib/src/ui/bloc/details_state.dart +++ b/lib/src/ui/bloc/details_state.dart @@ -3,7 +3,7 @@ part of 'details_bloc.dart'; @freezed class DetailsState with _$DetailsState { factory DetailsState({ - dynamic data, + TrackingMedium? data, @Default(TrackingMediumType.anime) TrackingMediumType trackingType, }) = _DetailsState; } diff --git a/lib/src/ui/pages/details.dart b/lib/src/ui/pages/details.dart index 0057a42..b2c88e2 100644 --- a/lib/src/ui/pages/details.dart +++ b/lib/src/ui/pages/details.dart @@ -40,30 +40,28 @@ class DetailsPage extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ AnimeCoverImage( - url: state.trackingType == TrackingMediumType.anime ? - (state.data as AnimeTrackingData).thumbnailUrl : - (state.data as MangaTrackingData).thumbnailUrl, + url: state.data!.thumbnailUrl, ), - Padding( - padding: const EdgeInsets.only( - left: 8, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - state.trackingType == TrackingMediumType.anime ? - (state.data as AnimeTrackingData).title : - (state.data as MangaTrackingData).title, - textAlign: TextAlign.left, - style: Theme.of(context).textTheme.titleLarge, - maxLines: 2, - softWrap: true, - overflow: TextOverflow.ellipsis, - ), - ], + Expanded( + child: Padding( + padding: const EdgeInsets.only( + left: 8, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + state.data!.title, + textAlign: TextAlign.left, + style: Theme.of(context).textTheme.titleLarge, + maxLines: 2, + softWrap: true, + overflow: TextOverflow.ellipsis, + ), + ], + ), ), ), ], @@ -114,9 +112,7 @@ class DetailsPage extends StatelessWidget { MediumTrackingState.dropped.toNameString(state.trackingType), ), ], - initialValue: state.trackingType == TrackingMediumType.anime ? - (state.data as AnimeTrackingData).state : - (state.data as MangaTrackingData).state, + initialValue: state.data!.state, ), ),