fluttercommunity / fluttercommunity/plus_plugins
[Bug]: Teams app file attachment issue using share_plus
- Lenguaje dominante
- Dart
- Estrellas
- 1.9k
- Forks
- 1.3k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
### Platform
Web (Chrome) Version 150.0.7871.129 (Official Build) (64-bit)
### Plugin
share_plus
### Version
12.0.2
### Flutter SDK
3.44.4
### Steps to reproduce
The issue appears to be related to the Teams cache. When I attach the same files using Outlook, they are attached successfully every time without any issues. There are no cases where two files are attached or where no file is attached. The attachment always matches the selected files. I have tried multiple solutions but it didn't work.
Solution 1: Use Unique File Paths & Force Cache Deletion (If Sharing Files)
If you are sharing files (like a PDF or CSV), Teams fails on the second attempt because the file name or path is identical, causing a cache collision in Teams. You must randomize the file name every single time using a timestamp or UUID.
```
import 'dart:io';import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';
Future shareToTeamsSafely(List fileBytes) async {
final tempDir = await getTemporaryDirectory();
// 1. Force a completely unique file name every single timefinal timestamp = DateTime.now().millisecondsSinceEpoch;
final file = File('${tempDir.path}/report_$timestamp.csv');
await file.writeAsBytes(fileBytes);
// 2. Share the unique fileawait Share.shareXFiles([XFile(file.path)]);
// 3. Clear your local reference after a slight delay so Teams can read it Future.delayed(Duration(seconds: 10), () async {
if (await file.exists()) {
await file.delete();
}
});
}
```
Solution 2: Deep Link directly via URL Launcher (If Sharing Text/Links)
If you are just sharing text or a URL, completely skip the system share sheet (and share_plus). Launching a direct [Microsoft Teams](https://www.microsoft.com/en-in/microsoft-teams/group-chat-software) deep link URL resets the Teams application state on every click, forcing it to open a fresh thread window.
Install [url_launcher](https://pub.dev/packages/url_launcher) and route the message directly:
```
import 'package:url_launcher/url_launcher.dart';
Future shareToTeamsDirectly(String message) async {
// Encode your text message safely for URLsfinal encodedMessage = Uri.encodeComponent(message);
// Deep link format for launching MS Teams chat/share channelfinal teamsUri = Uri.parse("https://microsoft.com");
if (await canLaunchUrl(teamsUri)) {
await launchUrl(teamsUri, mode: LaunchMode.externalApplication);
} else {
// Fallback if Teams app isn't installed on the deviceawait launchUrl(Uri.parse("https://live.com"));
}
}
```
Solution 3: The Native Reset Workaround (For Android Only)
If you are on Android and must use the native system sheet, the issue happens because the Intent.ACTION_SEND chooser flags aren't completely cleared by the OS when Teams remains running in the background. You can fix this by writing a custom Android Intent handler that flags the system to clear the task history on the second trigger.
Replace your Flutter share invocation with a method channel calling this native Android Kotlin code:
```
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "Your share text")
type = "text/plain"// Crucial flags to tell Android and Teams to open a brand new instance addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
}val chooser = Intent.createChooser(sendIntent, "Share via")
context.startActivity(chooser)
```
### Code Sample
```dart
```
### Logs
```shell
Error: Failed to execute 'share' on 'Navigator'
```
### Flutter Doctor
```shell
[√] Flutter (Channel stable, 3.44.4, on Microsoft Windows [Version 10.0.26200.8655], locale en-IN) [2.3s]
• Flutter version 3.44.4 on channel stable at C:\flutter_sdk\flutter_windows_3.44.4-stable\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ad70ec4617 (4 weeks ago), 2026-06-24 11:07:06 -0700
• Engine revision a10d8ac38d
• Dart version 3.12.2
• DevTools version 2.57.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations,
enable-native-assets, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
[√] Windows Version (Windows 11 or higher, 25H2, 2009) [3.9s]
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [2.1s]
• Android SDK at C:\Users\kketanbh\AppData\Local\Android\sdk
• Emulator version 36.5.10.0 (build_id 15081367) (CL:N/A)
X cmdline-tools component is missing.
Try installing or updating Android Studio.
Alternatively, download the tools from https://developer.android.com/studio#command-line-tools-only and make sure to set the ANDROID_HOME
environment variable.
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/to/windows-android-setup for more details.
[√] Chrome - develop for the web [717ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.14.31 (April 2026)) [715ms]
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
• Visual Studio Professional 2022 version 17.14.37216.2
• Windows 10 SDK version 10.0.26100.0
[√] Connected device (3 available) [1,702ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26200.8655]
• Chrome (web) • chrome • web-javascript • Google Chrome 150.0.7871.129
• Edge (web) • edge • web-javascript • Microsoft Edge 150.0.4078.83
[√] Network resources [1,715ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
```
### Checklist before submitting a bug
- [x] I searched issues in this repository and couldn't find such bug/problem
- [x] I Google'd a solution and I couldn't find it
- [x] I searched on StackOverflow for a solution and I couldn't find it
- [x] I read the README.md file of the plugin
- [x] I'm using the latest version of the plugin
- [x] All dependencies are up to date with `flutter pub upgrade`
- [x] I did a `flutter clean`
- [x] I tried running the example project
Guía de contribución
Línea de trabajo
Comienza reproduciendo el informe en el proyecto de ejemplo en Chrome 150 usando share_plus 12.0.2 y las versiones proporcionadas de Flutter y Dart. Compara el error de share de Navigator informado con el comportamiento de los adjuntos en Teams; el issue no menciona ningún archivo ni prueba del repositorio, por lo que completar esto requeriría un problema del plugin confirmado y aislado, así como una comprobación clara de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- dart, flutter
- Área
- web-dev
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 28/100