native_screenshot_pro 1.0.0 copy "native_screenshot_pro: ^1.0.0" to clipboard
native_screenshot_pro: ^1.0.0 copied to clipboard

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

example/lib/main.dart

import 'dart:io';

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

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

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

class _MyAppState extends State<MyApp> {
  Widget? _imgHolder;

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

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

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

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

                  if (path == null || path.isEmpty) {
                    if (path == null || path.isEmpty) {
                      WidgetsBinding.instance.addPostFrameCallback((_) {
                        ScaffoldMessenger.of(context).showSnackBar(
                          SnackBar(
                            content: Text('Error taking the screenshot :('),
                            backgroundColor: Colors.red,
                          ),
                        );
                      });
                      return;
                    }

                    return;
                  } // if error

                  WidgetsBinding.instance.addPostFrameCallback((_) {
                    ScaffoldMessenger.of(context).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
0
likes
160
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on native_screenshot_pro

Packages that implement native_screenshot_pro