Skip to content

Multiple widgets used the same GlobalKey #62

Description

@anaghvj

Getting GlobalKey Error

Multiple widgets used the same GlobalKey.

════════ Exception caught by widgets library ═══════════════════════════════════
Multiple widgets used the same GlobalKey.
════════════════════════════════════════════════════════════════════════════════

`The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [GlobalKey#beb1f] was used by multiple widgets. The parents of those widgets were:

  • CustomPaint(renderObject: RenderCustomPaint#830c9 NEEDS-PAINT)
  • CustomPaint(renderObject: RenderCustomPaint#e5d2c NEEDS-PAINT)
    A GlobalKey can only be specified on one widget at a time in the widget tree.

When the exception was thrown, this was the stack:
#6 BuildOwner.finalizeTree. (package:flutter/src/widgets/framework.dart:3177:11)
framework.dart:3177
#7 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3259:8)
framework.dart:3259
#8 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:992:19)
binding.dart:992
#9 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
binding.dart:448
#10 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
binding.dart:1386
#11 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
binding.dart:1311
#12 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:1034:7)
binding.dart:1034
#16 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 3 frames from class _Timer and dart:async-patch)`

How to reproduce:

SizedBox(
              width: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.height - 120 : MediaQuery.of(context).size.width - 120,
              height: MediaQuery.of(context).orientation == Orientation.portrait ? MediaQuery.of(context).size.width - 120 : MediaQuery.of(context).size.height - 140,
              child: AspectRatio(
                aspectRatio: 16 / 9,
                child: Card(
                  clipBehavior: Clip.hardEdge,
                  surfaceTintColor: EmintColors.emerald,
                  elevation: 0.2,
                  child: Scribble(
                    notifier: notifier,
                    drawPen: true,
                  ),
                ),
              ),
            ),

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions