Target Platform: Web
Target OS version/browser: Chrome
Devices: Chrome
RenderRepaintBoundary#toImage works on Android/iOS, not Web
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}'); | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |