-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Platform
android and ios
Plugin
share_plus
Version
latest
Flutter SDK
3.35.6
Steps to reproduce
Share with photo not works on android release and ios release versions, debug is working on both systems
Code Sample
UI part
Future<void> _shareScreenshot(BuildContext context, Rect origin) async {
try {
await Future.delayed(const Duration(milliseconds: 300));
final boundary =
_shareKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
if (boundary.debugNeedsPaint) {
await Future.delayed(const Duration(milliseconds: 300));
}
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData == null) throw Exception('Failed to convert image to bytes');
final pngBytes = byteData.buffer.asUint8List();
final dir = await getTemporaryDirectory();
final file = File(
'${dir.path}/horoscope_${DateTime.now().millisecondsSinceEpoch}.png',
);
await file.writeAsBytes(pngBytes);
await ShareUtil.shareFile(
filePath: file.path,
title: t.horoscope.horoscope,
sharePositionOrigin: origin,
);
} catch (e, st) {
debugPrint('Share error: $e');
debugPrint('$st');
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
e.toString(),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
backgroundColor: Colors.red,
),
);
}
}
} function
onTap: () {
final box =
buttonContext.findRenderObject()
as RenderBox?;
final origin =
(box != null && box.hasSize)
? (box.localToGlobal(Offset.zero) &
box.size)
: const Rect.fromLTWH(0, 0, 1, 1);
shareScreenshot(buttonContext, origin);
},
usage in onTap
util file helper
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:moonpaws/core/network/network_constants.dart';
import 'package:moonpaws/gen/strings.g.dart';
import 'package:share_plus/share_plus.dart';
final class ShareUtil {
ShareUtil._();
static final _instance = SharePlus.instance;
static Future<void> shareFile({
required String filePath,
required Rect sharePositionOrigin,
String? title,
}) async {
await SharePlus.instance.share(
ShareParams(
files: [XFile(filePath)],
subject: title,
text: t.shareUtil.shareText(
appLink:
Platform.isAndroid
? NetworkConstants.playStore
: NetworkConstants.appStore,
),
sharePositionOrigin: sharePositionOrigin,
),
);
}
static Future<void> share({
required String text,
required BuildContext context,
String? title,
}) async {
await _instance.share(ShareParams(text: text, title: title));
}
}Logs
the real erro i got in realease is LateInitializationError: Local 'result' has not been initialized.Flutter Doctor
[✓] Flutter (Channel stable, 3.35.6, on macOS 26.0.1 25A362 darwin-arm64, locale en-AM) [1,459ms]
• Flutter version 3.35.6 on channel stable at /Users/themaster/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 9f455d2486 (3 months ago), 2025-10-08 14:55:31 -0500
• Engine revision d2913632a4
• Dart version 3.9.2
• DevTools version 2.48.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-lldb-debugging
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [3.6s]
• Android SDK at /Users/themaster/Library/Android/sdk
• Emulator version 36.2.12.0 (build_id 14214601) (CL:N/A)
• Platform android-36, build-tools 36.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 26.0.1) [2.5s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17A400
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [6ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2025.2) [5ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
[✓] VS Code (version 1.107.1) [5ms]
• VS Code at /Users/themaster/Downloads/Visual Studio Code.app/Contents
• Flutter extension version 3.126.0
[✓] Connected device (3 available) [6.4s]
• iPhone 17 Pro Max (mobile) • 1C35A4C4-28E5-43D3-838D-7AD95D24420D • ios • com.apple.CoreSimulator.SimRuntime.iOS-26-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 26.0.1 25A362 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 143.0.7499.194
[✓] Network resources [1,398ms]
• All expected network resources are available.
• No issues found!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