Skip to content

save device_preview screenshots offline to device storage while developing or testing

License

Notifications You must be signed in to change notification settings

DonnC/preview_screenshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

save device_preview screenshots offline to device storage while developing or testing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published