3

I need to display an Image.memory in my project, but when I put this code in the body of Scaffold, it doesn't show.

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)
);
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
DavidY
  • 31
  • 1
  • 1
  • 3

3 Answers3

6
// 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
  );
}
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0
var img = "Here, I put the BASE64 string";
          final UriData? _data =  Uri.parse(img).data;
          myImage = _data!.contentAsBytes();

leading: CircleAvatar( radius: 50, child: Image.memory(myImage!), ),

zanzer
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 18 '22 at 10:45
0

If you just have a path for example /data/user/0/com.example.app/cache/311214142312/IMG5344234235.jpg,

you can use

Image.file(
  File(<the above path>)
)
Miro
  • 364
  • 1
  • 12