0

I'm not sure where to find the extra widget sharing the same global key as another widget in my app. I'm using the Screenshot and Social Share plugins.

https://pub.dev/packages/screenshot

https://pub.dev/packages/social_share

I'd like to upload a screenshot when sharing to social media such as Facebook Messenger. But I'm getting the following error in my console which occurred only after I added the screenshot controller;

Flutter Multiple widgets used the same GlobalKey

Where am I getting this problem? I created the screenshot instance within the state;

class _StageBuilderState extends State<StageBuilder> {
    ScreenshotController screenshotController = ScreenshotController();

Here's the build;

Widget createViewItem() {
    return Screenshot(
    controller: screenshotController,
          Column(
             children: <Widget>[
              child: Image.network( myavatar),
              child: IconButton(
                 icon: Icon(Icons.share),
                onPressed: () async {
                   await screenshotController.capture().then((image) async {
                   SocialShare.shareOptions("http://myurl", imagePath: image.path);
                      }
                   );
                 },
              ),
          ],
       ),
    ),
}

So where's this extra widget sharing the same global key as something else in my app? Where should I start troubleshooting?

Meggy
  • 1,491
  • 3
  • 28
  • 63

1 Answers1

1

Turns out I had to make the Screenshot controller local and put it here;

Widget createViewItem() {
   ScreenshotController _screenshotController = ScreenshotController();
    return Screenshot(
    controller: screenshotController,
          Column(
             children: <Widget>[
              child: Image.network( myavatar),
              child: IconButton(
                 icon: Icon(Icons.share),
                onPressed: () async {
                   await screenshotController.capture().then((image) async {
                   SocialShare.shareOptions("http://myurl", imagePath: image.path);
                      }
                   );
                 },
              ),
          ],
       ),
    ),
}

 
Meggy
  • 1,491
  • 3
  • 28
  • 63