/preview_screenshot

save device_preview screenshots offline to device storage while developing or testing

Primary LanguageDartBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

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.