Skip to content

Instantly share code, notes, and snippets.

@Sunbreak
Last active January 8, 2020 07:32
Show Gist options
  • Save Sunbreak/f0e6a0b0a3f058fb9b97f57bfdb3c50c to your computer and use it in GitHub Desktop.
Save Sunbreak/f0e6a0b0a3f058fb9b97f57bfdb3c50c to your computer and use it in GitHub Desktop.
`RenderRepaintBoundary#toImage` works on Android/iOS, not Web

ErrorReport

Target Platform: Web

Target OS version/browser: Chrome

Devices: Chrome

RenderRepaintBoundary#toImage works on Android/iOS, not Web

flutter/flutter#47721

ErrorReport

Target Platform: Web

Target OS version/browser: Chrome

Devices: Chrome

RenderRepaintBoundary#toImage works on Android/iOS, not Web

import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
final _boundaryKey = GlobalKey();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: RepaintBoundary(
key: _boundaryKey,
child: Container(
width: 200,
height: 100,
color: Colors.green,
),
),
),
floatingActionButton: FloatingActionButton(
child: Text('Test'),
onPressed: () async {
RenderRepaintBoundary b = _boundaryKey.currentContext.findRenderObject();
print('RenderRepaintBoundary $b');
var image = await b.toImage(pixelRatio: ui.window.devicePixelRatio);
var byteData = await image.toByteData();
print('byteData.lengthInBytes ${byteData.lengthInBytes}');
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment