Flutter: Rendering an Image from Byte Buffer/Int8List

Updated: July 14, 2022 By: A Goodman Post a comment

In Flutter, you can render an image from an Int8List of bytes by using the Image.memory constructor like so:


If what you have are byte buffers, use this:



This example does the following things:

  1. Reading byte data from a given URL of an image (you can change this step to suit your situation, such as fetch byte data from a file or from a database)
  2. Using Image.memory to render the image from byte data

The purpose of this example is to demonstrate what I mentioned earlier. In reality, the tiny app we’re going to build doesn’t make lots of sense because we can directly show an image with its URL instead of the detour of getting its bytes from the URL and then using this byte list to display the image.


The complete code:

// main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:typed_data';

void main() async {
  runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  Widget build(BuildContext context) {
    return MaterialApp(
      // Remove the debug banner
      debugShowCheckedModeBanner: false,
      title: 'KindaCode.com',
      theme: ThemeData(
        primarySwatch: Colors.pink,
      home: const HomeScreen(),

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  State<HomeScreen> createState() => _HomeScreenState();

class _HomeScreenState extends State<HomeScreen> {
  // this byte data will be used to render the image
  Int8List? _bytes;

  // get byte data from an image url
  void _getBytes(imageUrl) async {
    final ByteData data =
        await NetworkAssetBundle(Uri.parse(imageUrl)).load(imageUrl);
    setState(() {
      _bytes = data.buffer.asInt8List();

      // see how byte date of the image looks like

  void initState() {
    // call the _getBytes() function

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('KindaCode.com')),
      body: Center(
          child: _bytes == null
              ? const CircularProgressIndicator()
              : Image.memory(
                  width: 340,
                  height: 260,
                  fit: BoxFit.cover,

Mastering a skill involves continuous learning and a lot of practicing. Keep your motivation and stay on track by taking a look at the following Flutter articles:

You can also tour around our Flutter topic page or Dart topic page for the most recent tutorials and examples.

Notify of
Inline Feedbacks
View all comments

Related Articles