flutter_image_saver 1.0.1 copy "flutter_image_saver: ^1.0.1" to clipboard
flutter_image_saver: ^1.0.1 copied to clipboard

Simple and effective cross platform image saver for flutter, supported web and desktop.

example/lib/main.dart

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_image_saver/flutter_image_saver.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: Home());
  }
}

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  final repaintBoundary = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RepaintBoundary(
          key: repaintBoundary,
          child: const FlutterLogo(size: 120),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.download),
        onPressed: save,
      ),
    );
  }

  void save() async {
    final boundary = repaintBoundary.currentContext!.findRenderObject()!
        as RenderRepaintBoundary;
    final image = await boundary.toImage(pixelRatio: 2);
    final byteData = await image.toByteData(format: ImageByteFormat.png);
    final path = await saveImage(byteData!.buffer.asUint8List(), 'flutter.png');
    final message = path.isEmpty ? 'Saved' : 'Saved to $path';
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: Text(message)));
  }
}
4
likes
130
pub points
64%
popularity

Publisher

unverified uploader

Simple and effective cross platform image saver for flutter, supported web and desktop.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

cross_file, flutter, path_provider, permission_handler, universal_platform

More

Packages that depend on flutter_image_saver