Hola, tenemos la respuesta a lo que buscabas, continúa leyendo y la encontrarás más abajo.
Ejemplo: captura de widgets en flutter
import'package:flutter/material.dart';import'dart:async';import'dart:typed_data';import'dart:ui'as ui;import'package:flutter/material.dart';import'package:flutter/rendering.dart';import'package:flutter/services.dart';import'package:path_provider/path_provider.dart';import'dart:io';voidmain()=>runApp(newMyApp());classMyAppextendsStatelessWidget// This widget is the root of your application.
Widget build(BuildContext context)returnnewMaterialApp(
title:'Flutter Demo',
theme:newThemeData(
primarySwatch: Colors.blue,),
home:newMyHomePage(title:'Flutter Demo Home Page'),);classMyHomePageextendsStatefulWidgetMyHomePage(Key key,this.title):super(key: key);final String title;
_MyHomePageState createState()=>new_MyHomePageState();class_MyHomePageStateextendsState<MyHomePage>static GlobalKey previewContainer =newGlobalKey();
int _counter =0;void_incrementCounter()setState(()// This call to setState tells the Flutter framework that something has// changed in this State, which causes it to rerun the build method below// so that the display can reflect the updated values. If we changed// _counter without calling setState(), then the build method would not be// called again, and so nothing would appear to happen.
_counter++;);
Widget build(BuildContext context)returnRepaintBoundary(
key: previewContainer,
child:newScaffold(
appBar:newAppBar(
title:newText(widget.title),),
body:newCenter(
child:newColumn(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[newText('You have pushed the button this many times:',),newText('$_counter',
style: Theme.of(context).textTheme.display1,),newRaisedButton(
onPressed: takeScreenShot,
child:constText('Take a Screenshot'),),],),),
floatingActionButton:newFloatingActionButton(
onPressed: _incrementCounter,
tooltip:'Increment',
child:newIcon(Icons.add),),// This trailing comma makes auto-formatting nicer for build methods.));takeScreenShot()async
RenderRepaintBoundary boundary = previewContainer.currentContext.findRenderObject();
ui.Image image =await boundary.toImage();final directory =(awaitgetApplicationDocumentsDirectory()).path;
ByteData byteData =await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();print(pngBytes);
File imgFile =newFile('$directory/screenshot.png');
imgFile.writeAsBytes(pngBytes);
Si piensas que te ha sido provechoso nuestro post, sería de mucha ayuda si lo compartes con otros desarrolladores así contrubuyes a difundir nuestra información.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)