Giter Site home page Giter Site logo

donnc / preview_screenshot Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 7.86 MB

save device_preview screenshots offline to device storage while developing or testing

License: BSD 3-Clause "New" or "Revised" License

Kotlin 1.64% Swift 4.92% Objective-C 0.46% Dart 92.97%
flutter device-preview snippet dart

preview_screenshot's Introduction

preview_screenshot

device_preview take app screenshots offline to external storage

a small utility code to save device_preview screenshots ๐Ÿ“ฑ on device storage easily and offline, to easily copy or move them to upload to App Store (google play store application screenshots). Screenshots taken can be edited or uploaded as is to play store

  • โ— supports android for now

demo vid

Saved Screenshots

screenshot 1 screenshot 2 screenshot 3

Code snippets

in main.dart

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(
    DevicePreview(
      enabled: !kReleaseMode,
      onScreenshot: (screenshot) async {
        // invoked to save screenshot to user device storage
        final bytes = screenshot.bytes;
        final savedScreenshot = await savePreviewScreenshot(bytes: bytes, directory: 'DevicePreviewScreenshots');
        return savedScreenshot;
      },
      builder: (context) => MyApp(),

    ),
  );
}

function implementation savePreviewScreenshot(bytes: ..., directory: ...)

Future<String> savePreviewScreenshot({Uint8List bytes, String directory: 'DevicePreviewScreenshots'}) async {
  final bool _permissionStorage = await hasConfirmedStoragePermission();

  if (_permissionStorage) {
    final extDirectory = await ExtStorage.getExternalStorageDirectory();
    final dirName    = await Directory('$extDirectory/$directory').create(recursive: true);
    final fname     = 'screenshot-${DateTime.now().toIso8601String()}.png';
    final fileP     = '${dirName.path}/$fname';

    final File file = File(fileP);

    final _result = await file.writeAsBytes(bytes, mode: FileMode.writeOnly);

    return _result.path;
  }

  else {
    await askStoragePermission();
    return '';
  }
}

Plugins

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

preview_screenshot's People

Contributors

donnc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

stavares843

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.