GithubHelp home page GithubHelp logo

camiiloaf / take_screenshot Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 7 KB

Flutter Package to take screenshots in different ways and be able to share them in png format with other applications

License: MIT License

Dart 100.00%

take_screenshot's Introduction

take_screenshot

Package to take screenshots in different ways and be able to share them in png format with other applications

Getting Started

  1. Create Instance of Screenshot Controller
class MyHomePage extends StatelessWidget {
  final TakeScreenshotController _takeScreenshotController = TakeScreenshotController();

  ...
}
  1. Wrap the widget that you want to capture inside TakeScreenshot Widget. Assign the controller to takeScreenshotController that you have created earlier
TakeScreenshot(
    controller: _takeScreenshotController,
    child: WidgetToTakeScreenshot(),
),
  1. Take the screenshot by calling capture method. This print a Uint8List
try {
    final pngBytes = await _takeScreenshotController.captureAsPngBytes();
    print(pngBytes);
} on Exception catch (e) {
    print(e);
}

Full Example:

import 'package:flutter/material.dart';
import 'package:take_screenshot/take_screenshot.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Take Screenshot Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final TakeScreenshotController _takeScreenshotController = TakeScreenshotController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter TakeScreenshot Page'),
      ),
      body: TakeScreenshot(
        controller: _takeScreenshotController,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'Take your screenshot',
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          try {
            final pngBytes = await _takeScreenshotController.captureAsPngBytes();
            print(pngBytes);
          } on Exception catch (e) {
            print(e);
          }
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

Saving images to Specific Location

For this you can use captureAsFile method by passing directory location. By default, the captured image will be saved to Application Directory. Custom paths can be set using path parameter. Refer path_provider

Note

Method captureAsFile and captureAndShare are not supported for web.

Contributing

Contributions are welcomed!

Here is a list of how you can help:

  • Report bugs and scenarios that are difficult to implement
  • Report parts of the documentation that are unclear
  • Update the documentation / add examples
  • Implement new features by making a pull-request

take_screenshot's People

Contributors

camiiloaf avatar jcamiloagu avatar

Stargazers

 avatar

Watchers

 avatar

take_screenshot's Issues

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.