redesign user object

Serhii committed Feb 14, 2023 at 00:23 UTC 7235d8c9c23872de7706cacd3d39bb9215edbc34
2 files changed +36 -64
lib/entities/parse_address_from_domain.dart
+2 -2
@@ -45,11 +45,11 @@ class AddressResolver {
45 final formattedName = text.substring(1);
46 final twitterUser = await TwitterApi.lookupUserByName(userName: formattedName);
47 final addressFromBio = extractAddressByType(
48 - raw: twitterUser.data.description, type: CryptoCurrency.fromString(ticker));
48 + raw: twitterUser.description, type: CryptoCurrency.fromString(ticker));
49 if (addressFromBio != null) {
50 return ParsedAddress.fetchTwitterAddress(address: addressFromBio, name: text);
51 }
52 - final tweets = twitterUser.includes?.tweets;
52 + final tweets = twitterUser.tweets;
53 if (tweets != null) {
54 var subString = StringBuffer();
55 tweets.forEach((item) {
lib/twitter/twitter_user.dart
+34 -62
@@ -1,73 +1,45 @@
1 class TwitterUser {
2 - TwitterUser({
3 - required this.data,
4 - this.includes,
5 - });
6 -
7 - late final Data data;
8 - late final Includes? includes;
9 -
10 - TwitterUser.fromJson(Map<String, dynamic> json) {
11 - data = Data.fromJson(json['data'] as Map<String, dynamic>);
12 - includes = json['includes'] != null
13 - ? Includes.fromJson(json['includes'] as Map<String, dynamic>)
14 - : null;
15 - }
16 -}
17 -
18 -class Data {
19 - Data({
20 - required this.name,
21 - required this.id,
22 - required this.pinnedTweetId,
23 - required this.description,
24 - required this.username,
25 - });
26 -
27 - late final String name;
28 - late final String id;
29 - late final String? pinnedTweetId;
30 - late final String description;
31 - late final String username;
32 -
33 - Data.fromJson(Map<String, dynamic> json) {
34 - name = json['name'] as String;
35 - id = json['id'] as String;
36 - pinnedTweetId = json['pinned_tweet_id'] as String?;
37 - description = json['description'] as String;
38 - username = json['username'] as String;
39 - }
40 -}
41 -
42 -class Includes {
43 - Includes({
44 - required this.tweets,
45 - });
46 -
47 - late final List<Tweets> tweets;
48 -
49 - Includes.fromJson(Map<String, dynamic> json) {
50 - tweets = List.from(json['tweets'] as Iterable<dynamic>)
51 - .map((e) => Tweets.fromJson(e as Map<String, dynamic>))
52 - .toList();
2 + TwitterUser(
3 + {required this.id,
4 + required this.username,
5 + required this.name,
6 + required this.description,
7 + this.tweets});
8 +
9 + final String id;
10 + final String username;
11 + final String name;
12 + final String description;
13 + final List<Tweet>? tweets;
14 +
15 + factory TwitterUser.fromJson(Map<String, dynamic> json) {
16 + return TwitterUser(
17 + id: json['data']['id'] as String,
18 + username: json['data']['username'] as String,
19 + name: json['data']['name'] as String,
20 + description: json['data']['description'] as String,
21 + tweets: json['includes'] != null
22 + ? List.from(json['includes']['tweets'] as List)
23 + .map((e) => Tweet.fromJson(e as Map<String, dynamic>))
24 + .toList()
25 + : null,
26 + );
27 }
28 }
29
56 -class Tweets {
57 - Tweets({
58 - required this.editHistoryTweetIds,
30 +class Tweet {
31 + Tweet({
32 required this.id,
33 required this.text,
34 });
35
63 - late final List<String> editHistoryTweetIds;
64 - late final String id;
65 - late final String text;
36 + final String id;
37 + final String text;
38
67 - Tweets.fromJson(Map<String, dynamic> json) {
68 - editHistoryTweetIds =
69 - List.castFrom<dynamic, String>(json['edit_history_tweet_ids'] as List<dynamic>);
70 - id = json['id'] as String;
71 - text = json['text'] as String;
39 + factory Tweet.fromJson(Map<String, dynamic> json) {
40 + return Tweet(
41 + id: json['id'] as String,
42 + text: json['text'] as String,
43 + );
44 }
45 }