Code Monkey home page Code Monkey logo

share-files-and-screenshot-widgets-flutter's Introduction

share_files_and_screenshot_widgets

This pub lets you share any kind of files (csv, mp4, png etc), take screenshot of the widgets you want and return as Image and share them directly as well in the form of an image.

Usage

Example

To use this package :

  • add the dependency to your [pubspec.yaml] file.
  dependencies:
    flutter:
      sdk: flutter
    share_files_and_screenshot_widgets:

How to use

Take ScreenShot of Widgets

//define
GlobalKey previewContainer = new GlobalKey();

//wrap your widget with
RepaintBoundary(
  key: previewContainer,
  child: YourWidget()
),

//call this function for taking screenshot
ShareFilesAndScreenshotWidgets()
    .takeScreenshot(previewContainer, originalSize)
    .then((Image value) {
  setState(() {
    _image = value;
  });
});

Directly Share ScreenShot of Widgets

//define
GlobalKey previewContainer = new GlobalKey();

//wrap your widget with
RepaintBoundary(
  key: previewContainer,
  child: YourWidget()
),

//call this function for sharing screenshot
ShareFilesAndScreenshotWidgets().shareScreenshot(
  previewContainer,
  originalSize,
  "Title",
  "Name.png",
  "image/png",
  text: "This is the caption!");

Share Any Type of File

ByteData bytes =
    await rootBundle.load('assets/example.jpg');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
    "Title", "Name.jpg", list, "image/jpg",
    text: "This is the caption!");
ByteData bytes =
    await rootBundle.load('assets/example.mp4');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
    "Title", "Name.mp4", list, "video/mp4",
    text: "This is the caption!");
ByteData bytes =
    await rootBundle.load('assets/example.mp3');
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
    "Title", "Name.mp3", list, "audio/mp3",
    text: "This is the caption!");

License

Copyright 2020 Jay Mehta

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

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

Example

As time based...

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:ui';
import 'package:share_files_and_screenshot_widgets/share_files_and_screenshot_widgets.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter ScreenShot Demo',
      theme: ThemeData(
        primarySwatch: Colors.deepOrange,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo ScreenShot Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  Image _image;

  GlobalKey previewContainer = new GlobalKey();
  int originalSize = 800;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: SingleChildScrollView(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                RepaintBoundary(
                  key: previewContainer,
                  child: Container(
                    decoration: BoxDecoration(
                        border: Border.all(width: 1.5),
                        borderRadius: BorderRadius.circular(20),
                        color: Colors.deepPurple),
                    padding: EdgeInsets.all(15),
                    margin: EdgeInsets.all(20),
                    width: MediaQuery.of(context).size.width - 40,
                    height: MediaQuery.of(context).size.height,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        Text(
                          "This is a picture.",
                          style: TextStyle(
                              fontSize: 20,
                              fontWeight: FontWeight.bold,
                              color: Colors.white),
                        ),
                        Image.asset("assets/example.jpg"),
                        Text(
                          "There’s something so whimsical about these beautiful images that incorporate bokeh. It’s almost as if they could be from a different, magical world. We’ve loved watching the submissions fly in for our bokeh-themed Photo Quest by Meyer-Optik-Görlitz and selected 30+ of our favourites beautiful images to ignite your creative spark! The three lucky winners of this Quest are going to receive an incredible prize courtesy of master lens-crafters Meyer-Optik.",
                          style: TextStyle(color: Colors.white),
                        ),
                      ],
                    ),
                  ),
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Container(
                      child: RaisedButton(
                          child: Text("Take Screenshot!"),
                          onPressed: () {
                            ShareFilesAndScreenshotWidgets()
                                .takeScreenshot(previewContainer, originalSize)
                                .then((Image value) {
                              setState(() {
                                _image = value;
                              });
                            });
                          }),
                    ),
                    Container(
                        child: RaisedButton(
                            child: Text("Share Screenshot!"),
                            onPressed: () {
                              ShareFilesAndScreenshotWidgets().shareScreenshot(
                                  previewContainer,
                                  originalSize,
                                  "Title",
                                  "Name.png",
                                  "image/png",
                                  text: "This is the caption!");
                            })),
                    Container(
                        child: RaisedButton(
                            child: Text("Share Image!"),
                            onPressed: () async {
                              ByteData bytes =
                                  await rootBundle.load('assets/example.jpg');
                              Uint8List list = bytes.buffer.asUint8List();
                              ShareFilesAndScreenshotWidgets().shareFile(
                                  "Title", "Name.jpg", list, "image/jpg",
                                  text: "This is the caption!");
                            })),
                    Container(
                        child: RaisedButton(
                            child: Text("Share Video!"),
                            onPressed: () async {
                              ByteData bytes =
                                  await rootBundle.load('assets/example.mp4');
                              Uint8List list = bytes.buffer.asUint8List();
                              ShareFilesAndScreenshotWidgets().shareFile(
                                  "Title", "Name.mp4", list, "video/mp4",
                                  text: "This is the caption!");
                            })),
                    Container(
                        child: RaisedButton(
                            child: Text("Share Audio!"),
                            onPressed: () async {
                              ByteData bytes =
                                  await rootBundle.load('assets/example.mp3');
                              Uint8List list = bytes.buffer.asUint8List();
                              ShareFilesAndScreenshotWidgets().shareFile(
                                  "Title", "Name.mp3", list, "audio/mp3",
                                  text: "This is the caption!");
                            })),
                  ],
                ),
                _image != null ? _image : Center()
              ],
            ),
          ),
        ));
  }
}

share-files-and-screenshot-widgets-flutter's People

Contributors

jaytwwm avatar mrcsabatoth avatar rootasjey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

share-files-and-screenshot-widgets-flutter's Issues

About gif

Hello Team,

How can i share the gif ?

csv... how?

I was happy to see the csv share option, but there is no example for it in the docs. What is the file type? How to export it?
ShareFilesAndScreenshotWidgets().shareFile( "Title", "Name.csv", list, "text/csv", text: "This is the caption!");

Thanks!

This is the code i'm trying to get to work:

      final directory = await getApplicationDocumentsDirectory();

      File f = File('${directory.path}/mycsv.csv');

      String csv = const ListToCsvConverter().convert(data);

      await f.writeAsString(csv);

      var file_as_bytes = await f.readAsBytes();

      Uint8List list = file_as_bytes.buffer.asUint8List();

      ShareFilesAndScreenshotWidgets().shareFile(
          "Title", "Name.csv", list, "text/csv",
          text: "This is the caption!");

Namespace not specified. Specify a namespace in the module's build file

Steps to Reproduce

I depend on share_files_and_screenshot_widgets 1.0.6 in my app. I just tried to upgrade the Android side of the Flutter app to AGP 8.0+ (to be precise it's AGP 8.1 now), because Android Studio brings up the upgrade assistant for the last half year about this. The upgrade fails because some of the plugins don't have the namespace in their build.gradle. On of the failing plugins is the share_files_and_screenshot_widgets.

The build error message

A problem occurred configuring project ':share_files_and_screenshot_widgets'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

Code sample

Current build.gradle:

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

Expected (the way it is handled in Flutter Community plugins, along with he removal of the namespace from the AndroidManifest.xml):

android {
    // Conditional for compatibility with AGP <4.2.
    if (project.android.hasProperty("namespace")) {
        namespace 'com.twwm.share_files_and_screenshot_widgets'
    }

    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

Details

  • Platform: Android 12, OnePlus Nord EU (AC2003)
  • Flutter version: Channel beta, 3.13.0-0.2.pre
  • Development OS: Devuan GNU/Linux 6 (excalibur/ceres) 6.4.0-1-amd64, locale en_US.UTF-8
  • share_files_and_screenshot_widgets version: 1.0.6

  • I searched for similar issues already
  • I filled the details section with the exact device model and version
  • I am able to provide a reproducible example

Image cropped on a scroll

Hello I have a page with SingleChildScrollView, the image is generated and shared. The problem is that when the list is larger than the screen, the image is cropped.

image

Error permission

This my problem....

E/DatabaseUtils(21057): java.lang.SecurityException: Permission Denial: reading com.twwm.share_files_and_screenshot_widgets.ShareFilesAndScreenshotWidgetsFileProvider uri content://coesma.nit.eletronica.fileprovider.share_files_and_screenshot_widgets/cache/segundaviaAitNIT.png from pid=21789, uid=1000 requires the provider be exported, or grantUriPermission()

MissingPluginException

Unhandled Exception: MissingPluginException(No implementation found for method file on channel channel:share_files_and_screenshot_widget

Deprecated API Usage

.pub-cache/hosted/pub.dev/share_files_and_screenshot_widgets-1.0.6/android/src/main/java/com/twwm/share_files_and_screenshot_widgets/ShareFilesAndScreenshotWidgetsPlugin.java uses or overrides a deprecated API.

email subject

When sharing through email services (gmail/outlook),

the email's subject is always empty regardless of what i pass to .shareFile()
. the body of the email is filled successfully by the title in .shareFile() though.

how can i fill the email's Subject from .shareFile() ?

example:

ShareFilesAndScreenshotWidgets().shareFile(
        'title',  -> not used in email services
        'image.jpg',
        imageData,
        'image/jpg',
        text: "text", -> filled in email body
      );

edit: after further testing, sometimes in IOS devices the text parameter is the email subject AND email body. even more weird.

How to take screenshot of full screen ?

Hello I don't found how to dynamicaly take a full screen, originalSize is pixel dependant if I understand but I don't sucessed to make dynamic like MediaQuery.of(context).

thank you

Introduce null safety

Right now the package doesn't support null safety and that poses a problem with sound null safe projects.

The library 'package:share_files_and_screenshot_widgets/share_files_and_screenshot_widgets.dart' is legacy, and should not be imported into a null safe library.

Whatsapp share doesnt share the image

Hi,

When choosing the option to share to a whatsapp contact the screenshot is not shared, only the caption. Any other option (like facebook or email) do share the screenshot. What can be the issue here?

Marco

Security IOS 'Save Image'

Hi,

I'm getting a 'CRASHING_DUE_TO_PRIVACY_VIOLATION' error while choosing 'Save Image' in the share popup on iOS. What kind of security settings do i need for this option? I added some to the plist but i think i'm missing some.

Marco

Not Able to share Text with Video in Whats app

ByteData bytes = await rootBundle.load(playListLocalPath);
Uint8List list = bytes.buffer.asUint8List();
ShareFilesAndScreenshotWidgets().shareFile(
"Title", "Name.mp4", list, "video/mp4",
text: "This is the caption!"
);

Upgrade to Android V2 embedding to not rely on deprecated API

V2 is out there for a good while now and the time is ticking: Android Studio presents a warning

The plugins bluetooth_enable, share_files_and_screenshot_widgets use a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Some user can't take screenshot

Hello, I add this plugin in my app. It work's great for me on all my physical device and after release on playstore, but I have some feedback of users who can't take screenshot.. All users confirmed the validation of stockage authorization, but even this, their can't use this function.

thank you

offset on iOS

Hello, I have same trouble with other "screenshot and share" package. If I open share pop up, next I choose facebook, next I make fall the keyboard and after publish or cancel and close pop up, I have 1/4 of my screen with offset and impossible to remove without close app
RPReplay_Final1598707827

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.