fix(ui): Fix title overflow in details view

This commit is contained in:
PapaTutuWawa 2023-02-06 20:09:26 +01:00
parent a436b60ce8
commit b240870ebf
6 changed files with 44 additions and 36 deletions

View File

@ -6,7 +6,7 @@ part 'anime.g.dart';
/// Data about a tracked anime /// Data about a tracked anime
@freezed @freezed
class AnimeTrackingData with _$AnimeTrackingData{ class AnimeTrackingData with _$AnimeTrackingData, TrackingMedium {
factory AnimeTrackingData( factory AnimeTrackingData(
/// The ID of the anime /// The ID of the anime
String id, String id,

View File

@ -6,7 +6,7 @@ part 'manga.g.dart';
/// Data about a tracked anime /// Data about a tracked anime
@freezed @freezed
class MangaTrackingData with _$MangaTrackingData{ class MangaTrackingData with _$MangaTrackingData, TrackingMedium {
factory MangaTrackingData( factory MangaTrackingData(
/// The ID of the manga /// The ID of the manga
String id, String id,

View File

@ -15,6 +15,18 @@ enum MediumTrackingState {
all, 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 { extension MediumStateExtension on MediumTrackingState {
int toInteger() { int toInteger() {
assert(this != MediumTrackingState.all, 'MediumTrackingState.all must not be serialized'); assert(this != MediumTrackingState.all, 'MediumTrackingState.all must not be serialized');

View File

@ -16,7 +16,7 @@ final _privateConstructorUsedError = UnsupportedError(
/// @nodoc /// @nodoc
mixin _$DetailsState { mixin _$DetailsState {
dynamic get data => throw _privateConstructorUsedError; TrackingMedium? get data => throw _privateConstructorUsedError;
TrackingMediumType get trackingType => throw _privateConstructorUsedError; TrackingMediumType get trackingType => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
@ -29,7 +29,7 @@ abstract class $DetailsStateCopyWith<$Res> {
factory $DetailsStateCopyWith( factory $DetailsStateCopyWith(
DetailsState value, $Res Function(DetailsState) then) = DetailsState value, $Res Function(DetailsState) then) =
_$DetailsStateCopyWithImpl<$Res>; _$DetailsStateCopyWithImpl<$Res>;
$Res call({dynamic data, TrackingMediumType trackingType}); $Res call({TrackingMedium? data, TrackingMediumType trackingType});
} }
/// @nodoc /// @nodoc
@ -49,7 +49,7 @@ class _$DetailsStateCopyWithImpl<$Res> implements $DetailsStateCopyWith<$Res> {
data: data == freezed data: data == freezed
? _value.data ? _value.data
: data // ignore: cast_nullable_to_non_nullable : data // ignore: cast_nullable_to_non_nullable
as dynamic, as TrackingMedium?,
trackingType: trackingType == freezed trackingType: trackingType == freezed
? _value.trackingType ? _value.trackingType
: trackingType // ignore: cast_nullable_to_non_nullable : trackingType // ignore: cast_nullable_to_non_nullable
@ -65,7 +65,7 @@ abstract class _$$_DetailsStateCopyWith<$Res>
_$_DetailsState value, $Res Function(_$_DetailsState) then) = _$_DetailsState value, $Res Function(_$_DetailsState) then) =
__$$_DetailsStateCopyWithImpl<$Res>; __$$_DetailsStateCopyWithImpl<$Res>;
@override @override
$Res call({dynamic data, TrackingMediumType trackingType}); $Res call({TrackingMedium? data, TrackingMediumType trackingType});
} }
/// @nodoc /// @nodoc
@ -88,7 +88,7 @@ class __$$_DetailsStateCopyWithImpl<$Res>
data: data == freezed data: data == freezed
? _value.data ? _value.data
: data // ignore: cast_nullable_to_non_nullable : data // ignore: cast_nullable_to_non_nullable
as dynamic, as TrackingMedium?,
trackingType: trackingType == freezed trackingType: trackingType == freezed
? _value.trackingType ? _value.trackingType
: trackingType // ignore: cast_nullable_to_non_nullable : trackingType // ignore: cast_nullable_to_non_nullable
@ -103,7 +103,7 @@ class _$_DetailsState implements _DetailsState {
_$_DetailsState({this.data, this.trackingType = TrackingMediumType.anime}); _$_DetailsState({this.data, this.trackingType = TrackingMediumType.anime});
@override @override
final dynamic data; final TrackingMedium? data;
@override @override
@JsonKey() @JsonKey()
final TrackingMediumType trackingType; final TrackingMediumType trackingType;
@ -137,11 +137,11 @@ class _$_DetailsState implements _DetailsState {
abstract class _DetailsState implements DetailsState { abstract class _DetailsState implements DetailsState {
factory _DetailsState( factory _DetailsState(
{final dynamic data, {final TrackingMedium? data,
final TrackingMediumType trackingType}) = _$_DetailsState; final TrackingMediumType trackingType}) = _$_DetailsState;
@override @override
dynamic get data; TrackingMedium? get data;
@override @override
TrackingMediumType get trackingType; TrackingMediumType get trackingType;
@override @override

View File

@ -3,7 +3,7 @@ part of 'details_bloc.dart';
@freezed @freezed
class DetailsState with _$DetailsState { class DetailsState with _$DetailsState {
factory DetailsState({ factory DetailsState({
dynamic data, TrackingMedium? data,
@Default(TrackingMediumType.anime) TrackingMediumType trackingType, @Default(TrackingMediumType.anime) TrackingMediumType trackingType,
}) = _DetailsState; }) = _DetailsState;
} }

View File

@ -40,30 +40,28 @@ class DetailsPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
AnimeCoverImage( AnimeCoverImage(
url: state.trackingType == TrackingMediumType.anime ? url: state.data!.thumbnailUrl,
(state.data as AnimeTrackingData).thumbnailUrl :
(state.data as MangaTrackingData).thumbnailUrl,
), ),
Padding( Expanded(
padding: const EdgeInsets.only( child: Padding(
left: 8, padding: const EdgeInsets.only(
), left: 8,
child: Column( ),
mainAxisSize: MainAxisSize.min, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
state.trackingType == TrackingMediumType.anime ? Text(
(state.data as AnimeTrackingData).title : state.data!.title,
(state.data as MangaTrackingData).title, textAlign: TextAlign.left,
textAlign: TextAlign.left, style: Theme.of(context).textTheme.titleLarge,
style: Theme.of(context).textTheme.titleLarge, maxLines: 2,
maxLines: 2, softWrap: true,
softWrap: true, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, ),
), ],
], ),
), ),
), ),
], ],
@ -114,9 +112,7 @@ class DetailsPage extends StatelessWidget {
MediumTrackingState.dropped.toNameString(state.trackingType), MediumTrackingState.dropped.toNameString(state.trackingType),
), ),
], ],
initialValue: state.trackingType == TrackingMediumType.anime ? initialValue: state.data!.state,
(state.data as AnimeTrackingData).state :
(state.data as MangaTrackingData).state,
), ),
), ),