From 60f62f1ad611a2f8fba34b34887b1b8868dd00fa Mon Sep 17 00:00:00 2001 From: Mattia Date: Mon, 28 Feb 2022 12:32:52 +0100 Subject: [PATCH] Make ChannelAboutPage's description, viewCount, joinDate and country nullable. Fix #192 --- lib/src/channels/channel_about.dart | 8 +-- lib/src/channels/channel_about.freezed.dart | 72 +++++++++---------- .../pages/channel_about_page.dart | 28 ++++---- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/lib/src/channels/channel_about.dart b/lib/src/channels/channel_about.dart index fab6e4c..450525f 100644 --- a/lib/src/channels/channel_about.dart +++ b/lib/src/channels/channel_about.dart @@ -10,14 +10,14 @@ part 'channel_about.freezed.dart'; class ChannelAbout with _$ChannelAbout { const factory ChannelAbout( /// Full channel description. - String description, + String? description, /// Channel view count. - int viewCount, + int? viewCount, /// Channel join date. /// Formatted as: Gen 01, 2000 - String joinDate, + String? joinDate, /// Channel title. String title, @@ -26,7 +26,7 @@ class ChannelAbout with _$ChannelAbout { List thumbnails, /// Channel country. - String country, + String? country, /// Channel links. List channelLinks, diff --git a/lib/src/channels/channel_about.freezed.dart b/lib/src/channels/channel_about.freezed.dart index cf5e7e2..5dd3566 100644 --- a/lib/src/channels/channel_about.freezed.dart +++ b/lib/src/channels/channel_about.freezed.dart @@ -19,12 +19,12 @@ class _$ChannelAboutTearOff { const _$ChannelAboutTearOff(); _ChannelAbout call( - String description, - int viewCount, - String joinDate, + String? description, + int? viewCount, + String? joinDate, String title, List thumbnails, - String country, + String? country, List channelLinks) { return _ChannelAbout( description, @@ -44,14 +44,14 @@ const $ChannelAbout = _$ChannelAboutTearOff(); /// @nodoc mixin _$ChannelAbout { /// Full channel description. - String get description => throw _privateConstructorUsedError; + String? get description => throw _privateConstructorUsedError; /// Channel view count. - int get viewCount => throw _privateConstructorUsedError; + int? get viewCount => throw _privateConstructorUsedError; /// Channel join date. /// Formatted as: Gen 01, 2000 - String get joinDate => throw _privateConstructorUsedError; + String? get joinDate => throw _privateConstructorUsedError; /// Channel title. String get title => throw _privateConstructorUsedError; @@ -60,7 +60,7 @@ mixin _$ChannelAbout { List get thumbnails => throw _privateConstructorUsedError; /// Channel country. - String get country => throw _privateConstructorUsedError; + String? get country => throw _privateConstructorUsedError; /// Channel links. List get channelLinks => throw _privateConstructorUsedError; @@ -76,12 +76,12 @@ abstract class $ChannelAboutCopyWith<$Res> { ChannelAbout value, $Res Function(ChannelAbout) then) = _$ChannelAboutCopyWithImpl<$Res>; $Res call( - {String description, - int viewCount, - String joinDate, + {String? description, + int? viewCount, + String? joinDate, String title, List thumbnails, - String country, + String? country, List channelLinks}); } @@ -107,15 +107,15 @@ class _$ChannelAboutCopyWithImpl<$Res> implements $ChannelAboutCopyWith<$Res> { description: description == freezed ? _value.description : description // ignore: cast_nullable_to_non_nullable - as String, + as String?, viewCount: viewCount == freezed ? _value.viewCount : viewCount // ignore: cast_nullable_to_non_nullable - as int, + as int?, joinDate: joinDate == freezed ? _value.joinDate : joinDate // ignore: cast_nullable_to_non_nullable - as String, + as String?, title: title == freezed ? _value.title : title // ignore: cast_nullable_to_non_nullable @@ -127,7 +127,7 @@ class _$ChannelAboutCopyWithImpl<$Res> implements $ChannelAboutCopyWith<$Res> { country: country == freezed ? _value.country : country // ignore: cast_nullable_to_non_nullable - as String, + as String?, channelLinks: channelLinks == freezed ? _value.channelLinks : channelLinks // ignore: cast_nullable_to_non_nullable @@ -144,12 +144,12 @@ abstract class _$ChannelAboutCopyWith<$Res> __$ChannelAboutCopyWithImpl<$Res>; @override $Res call( - {String description, - int viewCount, - String joinDate, + {String? description, + int? viewCount, + String? joinDate, String title, List thumbnails, - String country, + String? country, List channelLinks}); } @@ -177,15 +177,15 @@ class __$ChannelAboutCopyWithImpl<$Res> extends _$ChannelAboutCopyWithImpl<$Res> description == freezed ? _value.description : description // ignore: cast_nullable_to_non_nullable - as String, + as String?, viewCount == freezed ? _value.viewCount : viewCount // ignore: cast_nullable_to_non_nullable - as int, + as int?, joinDate == freezed ? _value.joinDate : joinDate // ignore: cast_nullable_to_non_nullable - as String, + as String?, title == freezed ? _value.title : title // ignore: cast_nullable_to_non_nullable @@ -197,7 +197,7 @@ class __$ChannelAboutCopyWithImpl<$Res> extends _$ChannelAboutCopyWithImpl<$Res> country == freezed ? _value.country : country // ignore: cast_nullable_to_non_nullable - as String, + as String?, channelLinks == freezed ? _value.channelLinks : channelLinks // ignore: cast_nullable_to_non_nullable @@ -215,16 +215,16 @@ class _$_ChannelAbout implements _ChannelAbout { @override /// Full channel description. - final String description; + final String? description; @override /// Channel view count. - final int viewCount; + final int? viewCount; @override /// Channel join date. /// Formatted as: Gen 01, 2000 - final String joinDate; + final String? joinDate; @override /// Channel title. @@ -236,7 +236,7 @@ class _$_ChannelAbout implements _ChannelAbout { @override /// Channel country. - final String country; + final String? country; @override /// Channel links. @@ -283,27 +283,27 @@ class _$_ChannelAbout implements _ChannelAbout { abstract class _ChannelAbout implements ChannelAbout { const factory _ChannelAbout( - String description, - int viewCount, - String joinDate, + String? description, + int? viewCount, + String? joinDate, String title, List thumbnails, - String country, + String? country, List channelLinks) = _$_ChannelAbout; @override /// Full channel description. - String get description; + String? get description; @override /// Channel view count. - int get viewCount; + int? get viewCount; @override /// Channel join date. /// Formatted as: Gen 01, 2000 - String get joinDate; + String? get joinDate; @override /// Channel title. @@ -315,7 +315,7 @@ abstract class _ChannelAbout implements ChannelAbout { @override /// Channel country. - String get country; + String? get country; @override /// Channel links. diff --git a/lib/src/reverse_engineering/pages/channel_about_page.dart b/lib/src/reverse_engineering/pages/channel_about_page.dart index 5e8d167..9d04b56 100644 --- a/lib/src/reverse_engineering/pages/channel_about_page.dart +++ b/lib/src/reverse_engineering/pages/channel_about_page.dart @@ -10,13 +10,13 @@ import '../models/youtube_page.dart'; /// class ChannelAboutPage extends YoutubePage<_InitialData> { /// - String get description => initialData.description; + String? get description => initialData.description; /// - int get viewCount => initialData.viewCount; + int? get viewCount => initialData.viewCount; /// - String get joinDate => initialData.joinDate; + String? get joinDate => initialData.joinDate; /// String get title => initialData.title; @@ -25,7 +25,7 @@ class ChannelAboutPage extends YoutubePage<_InitialData> { List get avatar => initialData.avatar; /// - String get country => initialData.country; + String? get country => initialData.country; /// List get channelLinks => initialData.channelLinks; @@ -84,8 +84,8 @@ class _InitialData extends InitialData { .get('channelAboutFullMetadataRenderer')!; } - late final String description = - content.get('description')!.getT('simpleText')!; + late final String? description = + content.get('description')?.getT('simpleText'); late final List channelLinks = content .getList('primaryLinks') @@ -110,21 +110,21 @@ class _InitialData extends InitialData { .toList() ?? []; - late final int viewCount = int.parse(content - .get('viewCountText')! - .getT('simpleText')! - .stripNonDigits()); + late final int? viewCount = content + .get('viewCountText') + ?.getT('simpleText') + ?.parseInt(); - late final String joinDate = - content.get('joinedDateText')!.getList('runs')![1].getT('text')!; + late final String? joinDate = + content.get('joinedDateText')?.getList('runs')?[1].getT('text'); late final String title = content.get('title')!.getT('simpleText')!; late final List avatar = content.get('avatar')!.getList('thumbnails')!; - late final String country = - content.get('country')!.getT('simpleText')!; + late final String? country = + content.get('country')?.getT('simpleText'); Uri extractUrl(String text) => Uri.parse(Uri.decodeFull(_urlExp.firstMatch(text)?.group(1) ?? ''));