dev
dart 49 lines 1.29 KB
Raw
1 class TwitterUser {
2 TwitterUser(
3 {required this.id,
4 required this.username,
5 required this.name,
6 required this.description,
7 required this.location,
8 required this.profileImageUrl,
9 this.pinnedTweet});
10
11 final String id;
12 final String username;
13 final String name;
14 final String description;
15 final String location;
16 final String profileImageUrl;
17 final Tweet? pinnedTweet;
18
19 factory TwitterUser.fromJson(Map<String, dynamic> json, [Tweet? pinnedTweet]) {
20 final profileImageUrl = json['data']['profile_image_url'] as String? ?? '';
21 final scaledProfileImageUrl = profileImageUrl.replaceFirst('normal', '200x200');
22 return TwitterUser(
23 id: json['data']['id'] as String,
24 username: json['data']['username'] as String? ?? '',
25 name: json['data']['name'] as String,
26 description: json['data']['description'] as String? ?? '',
27 location: json['data']['location'] as String? ?? '',
28 profileImageUrl: scaledProfileImageUrl,
29 pinnedTweet: pinnedTweet,
30 );
31 }
32 }
33
34 class Tweet {
35 Tweet({
36 required this.id,
37 required this.text,
38 });
39
40 final String id;
41 final String text;
42
43 factory Tweet.fromJson(Map<String, dynamic> json) {
44 return Tweet(
45 id: json['id'] as String,
46 text: json['text'] as String,
47 );
48 }
49 }