Skip to content

Commit

Permalink
add new cover data for AppCard (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 authored Aug 14, 2024
1 parent f2a90eb commit 7bc9072
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/utils/web_view/web_view_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class _ShareMenuItem extends StatelessWidget {
true,
[],
'',
null,
);

await context.accountServer.sendAppCardMessage(
Expand Down
26 changes: 26 additions & 0 deletions lib/widgets/message/item/action_card/action_card_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppCardData {
this.shareable,
this.actions,
this.coverUrl,
this.cover,
);

factory AppCardData.fromJson(Map<String, dynamic> json) =>
Expand All @@ -28,6 +29,9 @@ class AppCardData {
final String iconUrl;
@JsonKey(name: 'cover_url', defaultValue: '')
final String coverUrl;

final Cover? cover;

final String title;
final String description;
@JsonKey(name: 'action', defaultValue: '')
Expand All @@ -47,6 +51,28 @@ class AppCardData {
bool get canShareActions => actions.every((e) => e.isValidSharedAction);
}

@JsonSerializable()
class Cover {
const Cover({
required this.url,
required this.thumbnail,
required this.mimeType,
required this.width,
required this.height,
});

factory Cover.fromJson(Map<String, dynamic> json) => _$CoverFromJson(json);

final String url;
final String? thumbnail;
@JsonKey(name: 'mime_type')
final String mimeType;
final int width;
final int height;

Map<String, dynamic> toJson() => _$CoverToJson(this);
}

extension on ActionData {
bool get isValidSharedAction {
try {
Expand Down
20 changes: 20 additions & 0 deletions lib/widgets/message/item/action_card/action_card_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion lib/widgets/message/item/action_card/actions_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

Expand Down Expand Up @@ -105,7 +107,9 @@ class ActionsCardBody extends StatelessWidget {
AspectRatio(
aspectRatio: 1,
child: CacheImage(data.coverUrl),
),
)
else if (data.cover != null)
_CoverWidget(cover: data.cover!),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
Expand All @@ -128,6 +132,26 @@ class ActionsCardBody extends StatelessWidget {
);
}

class _CoverWidget extends StatelessWidget {
const _CoverWidget({required this.cover});

final Cover cover;

@override
Widget build(BuildContext context) {
var aspect = 1.0;
try {
aspect = math.max(cover.width / cover.height, 1.5);
} catch (err) {
aspect = 1;
}
return AspectRatio(
aspectRatio: aspect,
child: CacheImage(cover.url),
);
}
}

class _Actions extends StatelessWidget {
const _Actions({required this.actions});

Expand Down

0 comments on commit 7bc9072

Please sign in to comment.