flutter - 如何显示 Image.memory
问题描述
我需要Image.memory
在我的项目中显示一个,但是当我将此代码放在body
of 中时Scaffold
,它不会显示。
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:convert';
Codec<String, String> stringToBase64 = utf8.fuse(base64);
String imagenJson = "Here, I put the BASE64 string";
Uint8List _image = base64Decode(imagenJson);
Image.memory(_image);
return Scaffold(
appBar: AppBar(
title: Text('Pruebas BASE64'),
),
body: Image.memory(_image)
);
解决方案
// Create an instance variable
Image image;
@override
void initState() {
super.initState();
// put them here
Codec<String, String> stringToBase64 = utf8.fuse(base64);
String imagenJson = "Here, I put the BASE64 string";
Uint8List _image = base64Decode(imagenJson);
image = Image.memory(_image); // assign it value here
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: image, // use it here
);
}
推荐阅读
- python - 如何在 Python 中使用 subprocess.run 运行这个包含引号的 tsduck shell 命令
- python - 在 python 中复制列表时使用 list() 的复杂性是什么?
- java - Docusign SDK for Java 可用于非 Web 应用程序
- promela - 我如何在 spin 中定义这样的宏?
- jquery - 每次按下按钮如何产生随机选项?
- sql - 选择雪花中字符串左侧的第一个单词
- vb.net - 如何将程序拆分为几个逻辑部分?
- javascript - 使用 querSelectorAll 获取所有子元素并添加到它们的 ClassList 时出现问题
- javascript - JsDocs:您如何记录工厂函数中的方法?
- python - 如何将文本文件转换为分隔的列表列表