【问题标题】:Flutter make BG image as local stored imageFlutter 将 BG 图像作为本地存储图像
【发布时间】:2019-01-31 07:01:23
【问题描述】:

我有以下代码将我的背景图片设置为资产图片:

Container(
   decoration: new BoxDecoration(
      image: DecorationImage(
         image: AssetImage("assets/bg.png"),
      )
   ),

我想知道我之前是否将图像存储到设备中,如何将其用作背景图像?

Future<File> _getLocalFile(String filename) async {
  String dir = (await getApplicationDocumentsDirectory()).path;
  File f = new File('$dir/$filename');
  return f;
}

谢谢。

【问题讨论】:

  • 您可以使用SharedPreferences 来跟踪您是否保存了上一张图片,然后执行您需要的操作。
  • 我确定图像已保存,但我如何访问它 - 我尝试使用 Image.file 但说我无法将 Image 转换为 ImageProvider
  • 在这种情况下使用FileImage
  • 谢谢,不知道 FileImage 类。

标签: image dart flutter


【解决方案1】:

FileImage 会有所帮助:

CircleAvatar(
   backgroundImage: FileImage(File(this.filepath)),
),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2013-02-02
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    相关资源
    最近更新 更多