1

我需要Image.memory在我的项目中显示一个,但是当我将此代码放在bodyof 中时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)
);
4

2 回答 2

2
// 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
  );
}
于 2019-09-10T04:14:07.540 回答
0
var img = "Here, I put the BASE64 string";
          final UriData? _data =  Uri.parse(img).data;
          myImage = _data!.contentAsBytes();

前导:CircleAvatar(半径:50,子:Image.memory(myImage!),),

于 2022-02-18T07:40:01.167 回答