Git Product home page Git Product logo

widgets_to_image's Introduction

Widgets To Image

A simple flutter package to export your widget to image with flutter

Installation

  1. Add this to your package's pubspec.yaml file:
dependencies:
  widgets_to_image: any
  1. Get the package using your IDE's GUI or via command line with
$ pub get
  1. Import the widgets_to_image.dart file in your app
import 'package:widgets_to_image/widgets_to_image.dart';

Usage

// WidgetsToImageController to access widget
WidgetsToImageController controller = WidgetsToImageController();
// to save image bytes of widget
Uint8List? bytes;

WidgetsToImage(
  controller: controller,
  child: cardWidget(),
),

final bytes = await controller.capture();

Screenshots

Mobile devices

phone

Web

phone

MacOS

phone

widgets_to_image's People

Contributors

mohamedabd0 avatar easazade avatar

Stargazers

Shujaat Ali Khan avatar Muhammad Altaaf avatar Andrii Syrokomskyi avatar Bear avatar 李伟 avatar Rakhim Abdullayev avatar  avatar  avatar Mohamed Abdo avatar Varshil J Patel avatar Duka7 avatar Minwoo Yun avatar CodeEagle avatar Chris avatar Mahir Taha Özdin avatar  avatar Hunter Wilhelm avatar  avatar  avatar 天南 avatar

Watchers

James Cloos avatar Victor Eronmosele avatar  avatar

widgets_to_image's Issues

Does not capture web view

This plugin does not capture web view when it is in the widget tree.

Relevant implementation details:
Webview: flutter_inappwebview: ^6.0.0-beta.22
Platform: iOS

InAppWebViewSettings(
    useHybridComposition: true,
    javaScriptEnabled: true,
    transparentBackground: true,
  );

Plugin version: widgets_to_image: ^0.0.2
Flutter 3.7.8

flutter 3.10.6 error

RenderView renderView = RenderView( child: RenderPositionedBox(alignment: alignment, child: repaintBoundary), configuration: ViewConfiguration( size: size, devicePixelRatio: devicePixelRatio, ), window: WidgetsBinding.instance!.platformDispatcher.views.first, );
Error: No named parameter with the name 'window'. widget_to_image.dart:32 window: WidgetsBinding.instance!.platformDispatcher.views.first, ^^^^^^

not working with ios app

got error like [ERROR:flutter/lib/ui/painting/image_encoding.cc(210)] Could not convert raster image to PNG.

not working on mobile

after test on mobile not working working only on emulator
final bytes =
await controller.capture();
setState(() {
this.bytes = bytes;
});
// MemoryImage(bytes!); // if commit or not not working
//Image.memory(this.bytes!); /// if commit or not not working
final image =
pw.MemoryImage(this.bytes!);

not working with ios app

error : [ERROR:flutter/lib/ui/painting/image_encoding.cc(210)] Could not convert raster image to PNG.

Assertion error in controller.capture() line

Getting below error for this line -
Uint8List? bytes = await widget.controller.capture();

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/rendering/proxy_box.dart': Failed assertion: line 3453 pos 12: '!debugNeedsPaint': is not true.
E/flutter ( 5923): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter ( 5923): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter ( 5923): #2      RenderRepaintBoundary.toImage (package:flutter/src/rendering/proxy_box.dart:3453:12)
E/flutter ( 5923): #3      WidgetsToImageController.capture (package:widgets_to_image/src/utils.dart:17:37)
E/flutter ( 5923): #4      PostActionsState.build.<anonymous closure> (package:tethys/views/posts/post_actions.dart:145:64)
E/flutter ( 5923): #5      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1072:21)
E/flutter ( 5923): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
E/flutter ( 5923): #7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11)
E/flutter ( 5923): #8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5)
E/flutter ( 5923): #9      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:276:7)
E/flutter ( 5923): #10     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:163:27)
E/flutter ( 5923): #11     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:464:20)
E/flutter ( 5923): #12     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
E/flutter ( 5923): #13     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:337:11)
E/flutter ( 5923): #14     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
E/flutter ( 5923): #15     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
E/flutter ( 5923): #16     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
E/flutter ( 5923): #17     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
E/flutter ( 5923): #18     _invoke1 (dart:ui/hooks.dart:167:13)
E/flutter ( 5923): #19     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:341:7)
E/flutter ( 5923): #20     _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
E/flutter ( 5923): 

not working with CameraPreview widget

I'm using camera plugin to take picture. my camera preview widget is a small widget not full screen. but when I take picture, the camera controller takes picture from full screen camera. So I wanted to use this package to take picture only the part is visible in my screen. but it takes a black image only.

                         ClipRRect(
                            borderRadius: BorderRadius.circular(3),
                            child: Transform.scale(
                              scale: cameraController!.value.aspectRatio,
                              child: AspectRatio(
                                aspectRatio:cameraController!.value.aspectRatio,
                                child: Center(
                                  child: WidgetsToImage(
                                    controller: takeDocPictureController.widgetsToImageController,
                                    child: CameraPreview(cameraController!),
                                  ),
                                ),
                              ),
                            ),
                          )

Error thrown on Null Check operator when converting widgets to images

I used this package for printing images using esc/pos thermal printer. A error thrown when trying to convert more than one widgets to images. The error caused by a null value of a variable - boundary in a function - capture() in utils.dart file

Future<Uint8List?> capture() async {
    try {
      /// boundary widget by GlobalKey
      RenderRepaintBoundary? boundary = containerKey.currentContext
          ?.findRenderObject() as RenderRepaintBoundary?;

      /// convert boundary to image
      final image = **await boundary!.toImage(pixelRatio: 6);**

Does a variable get nullified after converting a first widget?

'!debugNeedsPaint': is not true. ERROR

Hello.
I'm using your package well.
But When the capture() function was called, the following error pack occurred.

UI
WidgetsToImage(controller: controller.pollDocImageController, child: _buildPoll()),

GetXController
pollDocBytes.value = await pollDocImageController.capture() ?? Uint8List(0);

ERROR
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/rendering/proxy_box.dart': Failed assertion: line 3379 pos 12: '!debugNeedsPaint': is not true.

not working with flutter web.

it give me error as matrix4[0] == EngineFlutterDisplay.instance.devicePixelRatio &&
matrix4[5] == EngineFlutterDisplay.instance.devicePixelRatio
is not true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.