Flutter自适应卡片

Flutter 实现的自适应卡片。

安装

将此内容放入您的pubspec.yaml文件

dependencies:
  flutter_adaptive_cards:
    git:
      url: https://github.com/neohelden/Flutter-AdaptiveCards

使用方法

在Flutter中使用自适应卡片非常简单:您只需要AdaptiveCard小部件。

有几个构造函数可以处理来自不同来源的数据加载。

AdaptiveCard.network接受一个URL来下载并显示有效负载。
AdaptiveCard.asset接受一个资源路径来从本地数据加载有效负载。
AdaptiveCard.memory接受一个映射(可以通过使用json类解码字符串获得)并显示它。

一个例子

AdaptiveCard.network(
  placeholder: Text("Loading, please wait"),
  url: "www.someUrlThatPoints.To/A.json",
  hostConfigPath: "assets/host_config.json",
  onSubmit: (map) {
    // Send to server or handle locally
  },
  onOpenUrl: (url) {
    // Open url using the browser or handle differently
  },
  // If this is set, a button will appear next to each adaptive card which when clicked shows the payload.
  // NOTE: this will only be shown in debug mode, this attribute does change nothing for realease builds.
  // This is very useful for debugging purposes
  showDebugJson: true,
  // If you have not implemented explicit dark theme, Adaptive Cards will try to approximate its colors to match the dark theme
  // so the contrast and color meaning stays the same.
  // Turn this off, if you want to have full control over the colors when using the dark theme.
  // NOTE: This is currently still under development
  approximateDarkThemeColors: true,
);

运行测试

只需输入

flutter test

并要更新黄金文件,请运行

flutter test --update-goldens test/sample_golden_test.dart

这将更新示例卡片的黄金文件。

GitHub

https://github.com/neohelden/Flutter-AdaptiveCards