flutter 如何显示图像,记忆

ukxgm1gy  于 2023-05-01  发布在  Flutter
关注(0)|答案(3)|浏览(145)

我需要在我的项目中显示一个Image.memory,但是当我把这个代码放在Scaffoldbody中时,它没有显示。

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)
);
mi7gmzs6

mi7gmzs61#

// 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
  );
}
ryoqjall

ryoqjall2#

var img = "Here, I put the BASE64 string";
          final UriData? _data =  Uri.parse(img).data;
          myImage = _data!.contentAsBytes();

行距:CircleAvatar(radius:50岁,孩子:形象。memory(myImage!),),

qxgroojn

qxgroojn3#

如果你只有一个路径,例如/data/user/0/com.example.app/cache/311214142312/IMG5344234235.jpg
你可以用

Image.file(
  File(<the above path>)
)

相关问题