Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
Get Widget Share Position Origin

Flutter Widget Share Position Origin

Posted on January 25, 2026 by Toma Velev

To get the sharePositionOrigin from a specific Flutter Widget, you need to determine that widget’s position and size in the global coordinate space. This is essential for iPad and macOS users, as the share sheet needs an anchor point to point its “arrow” toward.

The most reliable way to do this is by using the widget’s BuildContext to find its RenderBox.

The Core Logic

You can calculate the required Rect using this pattern:


final RenderBox? box = context.findRenderObject() as RenderBox?;

if (box != null) {
final Rect sharePositionOrigin = box.localToGlobal(Offset.zero) & box.size;

// Use it in your share call
await Share.share(
‘Check out this cool content!’,
sharePositionOrigin: sharePositionOrigin,
);
}

Implementation Strategies

Depending on how your code is structured, you have two primary ways to access the correct BuildContext.

  1. Using a Builder Widget (Easiest)

If you are calling the share function inside an onPressed callback, the standard context might refer to the entire page rather than the specific button. A Builder provides a local context specific to that button.


Builder(
   builder: (BuildContext context) {
    return ElevatedButton(
      onPressed: () {
        final box = context.findRenderObject() as RenderBox?;
        final rect = box!.localToGlobal(Offset.zero) & box.size;
    Share.share(
      'Hello from Flutter!',
      sharePositionOrigin: rect,
    );
  },
  child: const Text('Share'),
);

},
)

  1. Using a GlobalKey

If you need to trigger the share from a different part of the code but anchor it to a specific widget, use a GlobalKey.

Define the key: final GlobalKey _shareKey = GlobalKey();

Assign the key: (key: _shareKey, …)

Calculate the Rect:



final box = _shareKey.currentContext?.findRenderObject() as RenderBox?;
if (box != null) {
  final rect = box.localToGlobal(Offset.zero) & box.size;
  // Share...
}

Why this works

Flutter uses a coordinate system where each widget has its own local (0,0) position.

localToGlobal(Offset.zero): Converts the widget’s local (0,0) top-left corner into the global (x, y) coordinates of the screen.

& box.size: This is a Flutter operator overload that combines an Offset (the position) and a Size to create a Rect.

Note: If you don’t provide a sharePositionOrigin on an iPad, the app may crash when the share sheet tries to open, as it won’t know where to attach the popover.

  • Join iOS Beta Testing Explained
  • Firebase App Distribution Setup
  • iOS App Lifetime Unverified
  • Flutter Bottom Border
  • Get Flutter current time zone

Categories

  • Apps (25)
  • ChatGPT (24)
  • Choosing a Framework (38)
  • Flutter (279)
  • Graphical User Interface (14)
  • Marketing (118)
  • Software Development (288)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (4)
  • Uncategorized (14)
  • Vaadin (15)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (86)
    • Flutter Apps (26)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Join iOS Beta Testing Explained
  • Firebase App Distribution Setup
  • iOS App Lifetime Unverified
  • Flutter Bottom Border
  • Get Flutter current time zone

Post Categories

  • Apps (25)
  • ChatGPT (24)
  • Choosing a Framework (38)
  • Flutter (279)
  • Graphical User Interface (14)
  • Marketing (118)
  • Software Development (288)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (4)
  • Uncategorized (14)
  • Vaadin (15)