"how to convert base64 string into image with flutter?" Code Answer


you can convert a uint8list to a flutter image widget using the image.memory constructor. (use the uint8list.fromlist constructor to convert a list to uint8list if necessary.) you can use base64.encode to go the other way.

here's some sample code.

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runapp(new myapp());

class myapp extends statelesswidget {
  widget build(buildcontext context) {
    return new materialapp(
      theme: new themedata.dark(),
      home: new myhomepage(),

class myhomepage extends statefulwidget {
  state createstate() => new myhomepagestate();

class myhomepagestate extends state<myhomepage> {
  string _base64;

  void initstate() {
    (() async {
      http.response response = await http.get(
      if (mounted) {
        setstate(() {
          _base64 = base64.encode(response.bodybytes);

  widget build(buildcontext context) {
    if (_base64 == null)
      return new container();
    uint8list bytes = base64.decode(_base64);
    return new scaffold(
      appbar: new appbar(title: new text('example app')),
      body: new listtile(
        leading: new image.memory(bytes),
        title: new text(_base64),

however, it's generally a bad idea to store large blobs of binary data in your database. it's not playing to the strengths of firebase realtime database and you will end up wasting bandwidth transmitting data you don't need as well as unnecessary encoding and decoding. you should use the firebase_storage plugin instead, storing the path or download url of the image in the database.

By Wilson Hauck on June 19 2022

Answers related to “how to convert base64 string into image with flutter?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.