Flutter – I want to display it on the screen right away rather than a file after the screenshot is taken


By using RepaintBoundary, you can capture only the desired area.

I want to make the screenshot appear right on the screen as soon as you take it.


You can just store the bytes in a variable, and display it using Image.memory().


Press the "Download" button in the middle, to screenshot and display it.


Full source code:

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

void main() {

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),

class MyHomePage extends StatefulWidget {
  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  GlobalKey _globalKey = GlobalKey();
  var _bytes;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Screenshot Example")),
      body: Column(
        children: [
          /// Area to be captured
            key: _globalKey,
            child: Container(
              width: 300,
              height: 300,
              decoration: BoxDecoration(
                gradient: RadialGradient(
                  colors: [Colors.white, Colors.grey],
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("screenshot me"),

          /// Button
            icon: Icon(Icons.file_download),
            onPressed: () async {
              final render = (_globalKey.currentContext!.findRenderObject()
                  as RenderRepaintBoundary);
              final imageBytes = (await (await render.toImage())
                      .toByteData(format: ImageByteFormat.png))!
              setState(() {
                _bytes = imageBytes;

          /// Display
          if (_bytes != null) Image.memory(_bytes, width: 200),

Answered By – user1032613

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *