Flutter share plus: Sharing image and text on WhatsApp
Asked Answered
K

1

7

I'm trying to implement a function to my flutter application so that if a user presses on a specific button an image and a text shall be shared via mail, WhatsApp, etc. I used the share_plus plugin and the screenshot plugin. So far I managed to get it to work when I share it via mail but when I'm trying to share the image+text via WhatsApp it won't work. It will only share the text and the image is always missing. When I delete the text and only share an image, everything works well on WhatsApp. Can you please help me? Thank you so much!

import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:typed_data';
import 'package:screenshot/screenshot.dart';
import 'dart:io';
class InfoScreen extends StatelessWidget {
  final controller = ScreenshotController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Info'),
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [Color(0xffFBD23E), Color(0xffF6BE03)],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter),
          ),
        ),
      ),
      body: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
              colors: [Color(0xffFEFDFD), Color(0xffBDBDB2)],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight),
        ),
        child: Column(
          children: <Widget>[
ButtonTheme(
              minWidth: 10000,
              height: 45,
              child: Padding(
                padding: EdgeInsets.fromLTRB(15, 2, 15, 15),
                child: Align(
                  alignment: Alignment.topCenter,
                  child: RaisedButton(
                    onPressed: () async {
                      final image = await controller
                          .captureFromWidget(buildImageStartseite());
                      saveAndShare(image);
                    },
                    color: Colors.white,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(12.0),
                        bottomRight: Radius.circular(12.0),
                      ),
                    ),
                    highlightColor: Color(0xffB4B4B3),
                    splashColor: Colors.transparent,
                    child: Text(
                      'Press to share',
                      textAlign: TextAlign.center,
                      style: TextStyle(fontSize: 17, color: Color(0xff232323)),
                    ),
                  ),
                ),
              ),
            ),
],
        ),
      ),
    );
  }


  Future saveAndShare(Uint8List bytes) async {
    final directory = await getApplicationDocumentsDirectory();
    final image = File('${directory.path}/Shared_picture.png');
    image.writeAsBytesSync(bytes);
    final text =
        'I'm sharing this with you!';
    await Share.shareFiles([image.path], text: text);
  }
}
Kluge answered 4/10, 2021 at 16:33 Comment(6)
I have the same issue, did you find a resolution?E
I guess this is a common issue. With the share plus plugin it is not possible to share a text and an image at the same time.Kluge
It is working on android but not working on iosPaoting
I am also facing the same issue @Kluge have you found any work aroundUyekawa
I am also facing this issue @Kluge Have you solved or any work around?Misbehave
Reached here with the same problem and so solution found until nowStructural
C
4

This is a known issue of the share_plus plugin with no known workarounds aside from sending the image and text separately. Both file and text can't be shared on WhatsApp at the same time as mentioned in this issue ticket. This is due to limitations on Facebook's implementation on their messaging apps as discussed on this thread.

Convince answered 13/1, 2023 at 12:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.