Skip to content

Commit 7bc9072

Browse files
authored
add new cover data for AppCard (#1637)
1 parent f2a90eb commit 7bc9072

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

lib/utils/web_view/web_view_mobile.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class _ShareMenuItem extends StatelessWidget {
294294
true,
295295
[],
296296
'',
297+
null,
297298
);
298299

299300
await context.accountServer.sendAppCardMessage(

lib/widgets/message/item/action_card/action_card_data.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AppCardData {
1717
this.shareable,
1818
this.actions,
1919
this.coverUrl,
20+
this.cover,
2021
);
2122

2223
factory AppCardData.fromJson(Map<String, dynamic> json) =>
@@ -28,6 +29,9 @@ class AppCardData {
2829
final String iconUrl;
2930
@JsonKey(name: 'cover_url', defaultValue: '')
3031
final String coverUrl;
32+
33+
final Cover? cover;
34+
3135
final String title;
3236
final String description;
3337
@JsonKey(name: 'action', defaultValue: '')
@@ -47,6 +51,28 @@ class AppCardData {
4751
bool get canShareActions => actions.every((e) => e.isValidSharedAction);
4852
}
4953

54+
@JsonSerializable()
55+
class Cover {
56+
const Cover({
57+
required this.url,
58+
required this.thumbnail,
59+
required this.mimeType,
60+
required this.width,
61+
required this.height,
62+
});
63+
64+
factory Cover.fromJson(Map<String, dynamic> json) => _$CoverFromJson(json);
65+
66+
final String url;
67+
final String? thumbnail;
68+
@JsonKey(name: 'mime_type')
69+
final String mimeType;
70+
final int width;
71+
final int height;
72+
73+
Map<String, dynamic> toJson() => _$CoverToJson(this);
74+
}
75+
5076
extension on ActionData {
5177
bool get isValidSharedAction {
5278
try {

lib/widgets/message/item/action_card/action_card_data.g.dart

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/widgets/message/item/action_card/actions_card.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math' as math;
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_hooks/flutter_hooks.dart';
35

@@ -105,7 +107,9 @@ class ActionsCardBody extends StatelessWidget {
105107
AspectRatio(
106108
aspectRatio: 1,
107109
child: CacheImage(data.coverUrl),
108-
),
110+
)
111+
else if (data.cover != null)
112+
_CoverWidget(cover: data.cover!),
109113
const SizedBox(height: 10),
110114
Padding(
111115
padding: const EdgeInsets.symmetric(horizontal: 12),
@@ -128,6 +132,26 @@ class ActionsCardBody extends StatelessWidget {
128132
);
129133
}
130134

135+
class _CoverWidget extends StatelessWidget {
136+
const _CoverWidget({required this.cover});
137+
138+
final Cover cover;
139+
140+
@override
141+
Widget build(BuildContext context) {
142+
var aspect = 1.0;
143+
try {
144+
aspect = math.max(cover.width / cover.height, 1.5);
145+
} catch (err) {
146+
aspect = 1;
147+
}
148+
return AspectRatio(
149+
aspectRatio: aspect,
150+
child: CacheImage(cover.url),
151+
);
152+
}
153+
}
154+
131155
class _Actions extends StatelessWidget {
132156
const _Actions({required this.actions});
133157

0 commit comments

Comments
 (0)