Description
Platform
Windows 11
Plugin
share_plus
Version
11.0.0
Flutter SDK
3.29.3
Steps to reproduce
I have prepared a complete example illustrating all aspects of the problem.
-
share1: Sending a file created via xFile.fromData is impossible.
1.1: If sent without text, there will be an empty window.1.2 If sent with text, only the text will be sent.
-
share2: Sending a manually written file encounters undocumented limitations.
2.1: Sending a file without text is impossible.2.2 Sending with text works normally.
2.3 Sending with text and deleting the file leads to a result similar to 1.2: only the text will be sent. -
The results described for "without sending text" cease to be relevant after calling one of the methods for sending with text. share_plus tries to send the old text sent previously, even if it is not passed in the current call.
The saved text is reset after a full restart of the program (not a hot restart).
Code Sample
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
import 'package:path/path.dart' as path;
void main() {
runApp(const MainApp());
}
void share1([bool includeText = false]) async {
final String testContent = 'Test';
final Uint8List bytes = utf8.encode(testContent);
final xfile = XFile.fromData(bytes);
await SharePlus.instance.share(
ShareParams(files: [xfile], text: includeText ? 'Test' : null),
);
}
void share2([bool includeText = false, bool deleteFile = false]) async {
final String testContent = 'Test';
final Uint8List bytes = utf8.encode(testContent);
final temp = (await getTemporaryDirectory()).path;
final filePath = path.join(temp, 'test.txt');
var file = File(filePath);
await file.writeAsBytes(bytes);
await SharePlus.instance.share(
ShareParams(files: [XFile(filePath)], text: includeText ? 'Test' : null),
);
if (deleteFile) await file.delete();
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
spacing: 16,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: share1, child: Text('Share1')),
ElevatedButton(
onPressed: () => share1(true),
child: Text('Share1 with text'),
),
ElevatedButton(onPressed: share2, child: Text('Share2')),
ElevatedButton(
onPressed: () => share2(true),
child: Text('Share2 with text'),
),
ElevatedButton(
onPressed: () => share2(false, true),
child: Text('Share2 with delete'),
),
ElevatedButton(
onPressed: () => share2(true, true),
child: Text('Share2 with text and delete'),
),
],
),
),
),
);
}
}
Logs
-
Flutter Doctor
-
Checklist before submitting a bug
- I searched issues in this repository and couldn't find such bug/problem
- I Google'd a solution and I couldn't find it
- I searched on StackOverflow for a solution and I couldn't find it
- I read the README.md file of the plugin
- I'm using the latest version of the plugin
- All dependencies are up to date with
flutter pub upgrade
- I did a
flutter clean
- I tried running the example project