native_screenshot 0.0.2+2 copy "native_screenshot: ^0.0.2+2" to clipboard
native_screenshot: ^0.0.2+2 copied to clipboard

outdated

A simple plugin to take screenshots using native code (iOS & Android).

example/lib/main.dart

import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:native_screenshot/native_screenshot.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  Widget _imgHolder;

  @override
  void initState() {
    super.initState();

    _imgHolder = Center(
      child: Icon(Icons.image),
    );
  } // initState()

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text('NativeScreenshot Example'),
        ),
        bottomNavigationBar: ButtonBar(
          alignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text('Press to capture screenshot'),
              onPressed: () async {
                String path = await NativeScreenshot.takeScreenshot();

                debugPrint('Screenshot taken, path: $path');

                if( path == null || path.isEmpty ) {
                  _scaffoldKey.currentState.showSnackBar(
                    SnackBar(
                      content: Text('Error taking the screenshot :('),
                      backgroundColor: Colors.red,
                    )
                  ); // showSnackBar()

                  return;
                } // if error

                _scaffoldKey.currentState.showSnackBar(
                  SnackBar(
                    content: Text('The screenshot has been saved to: $path')
                  )
                ); // showSnackBar()

                File imgFile = File(path);
                _imgHolder = Image.file(imgFile);

                setState(() {});
              },
            )
          ],
        ),
        body: Container(
          constraints: BoxConstraints.expand(),
          child: _imgHolder,
        ),
      ),
    );
  } // build()
} // _MyAppState
57
likes
0
pub points
89%
popularity

Publisher

unverified uploader

A simple plugin to take screenshots using native code (iOS & Android).

Homepage
Repository
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on native_screenshot