diff --git a/lib/src/layer/attribution_layer/rich.dart b/lib/src/layer/attribution_layer/rich.dart index 11c0e0bec..281f22dec 100644 --- a/lib/src/layer/attribution_layer/rich.dart +++ b/lib/src/layer/attribution_layer/rich.dart @@ -153,9 +153,6 @@ class RichAttributionWidget extends StatefulWidget { class RichAttributionWidgetState extends State { StreamSubscription? mapEventSubscription; - final persistentAttributionKey = GlobalKey(); - Size? persistentAttributionSize; - late bool popupExpanded = widget.popupInitialDisplayDuration != Duration.zero; bool persistentHovered = false; @@ -173,22 +170,6 @@ class RichAttributionWidgetState extends State { }, ); } - - WidgetsBinding.instance.addPostFrameCallback( - (_) => WidgetsBinding.instance.addPostFrameCallback( - (_) { - assert( - persistentAttributionKey.currentContext?.findRenderObject() != null, - 'persistentAttributionKey is not in the widget tree', - ); - final renderObject = - persistentAttributionKey.currentContext?.findRenderObject(); - if (renderObject is RenderBox) { - setState(() => persistentAttributionSize = renderObject.size); - } - }, - ), - ); } @override @@ -255,88 +236,78 @@ class RichAttributionWidgetState extends State { ), ]; - return LayoutBuilder( - builder: (context, constraints) => Align( + return Align( + alignment: widget.alignment.real, + child: Stack( alignment: widget.alignment.real, - child: Stack( - alignment: widget.alignment.real, - children: [ - if (persistentAttributionSize != null) - Padding( - padding: const EdgeInsets.all(6), - child: widget.animationConfig.popupAnimationBuilder( - context: context, - isExpanded: popupExpanded, - config: widget, - child: Container( - decoration: BoxDecoration( - color: widget.popupBackgroundColor ?? - Theme.of(context).colorScheme.background, - border: Border.all(width: 0, style: BorderStyle.none), - borderRadius: widget.popupBorderRadius ?? - BorderRadius.only( - topLeft: const Radius.circular(10), - topRight: const Radius.circular(10), - bottomLeft: widget.alignment == - AttributionAlignment.bottomLeft + children: [ + Padding( + padding: const EdgeInsets.all(6), + child: widget.animationConfig.popupAnimationBuilder( + context: context, + isExpanded: popupExpanded, + config: widget, + child: Container( + decoration: BoxDecoration( + color: widget.popupBackgroundColor ?? + Theme.of(context).colorScheme.background, + border: Border.all(width: 0, style: BorderStyle.none), + borderRadius: widget.popupBorderRadius ?? + BorderRadius.only( + topLeft: const Radius.circular(10), + topRight: const Radius.circular(10), + bottomLeft: + widget.alignment == AttributionAlignment.bottomLeft ? Radius.zero : const Radius.circular(10), - bottomRight: widget.alignment == - AttributionAlignment.bottomRight + bottomRight: + widget.alignment == AttributionAlignment.bottomRight ? Radius.zero : const Radius.circular(10), - ), - ), - constraints: BoxConstraints( - minWidth: constraints.maxWidth < 420 - ? constraints.maxWidth - : persistentAttributionSize!.width, - ), - child: Padding( - padding: const EdgeInsets.all(8), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ...widget.attributions - .whereType(), - const TextSourceAttribution( - "Made with 'flutter_map'", - prependCopyright: false, - textStyle: TextStyle(fontStyle: FontStyle.italic), - ), - SizedBox(height: (widget.permanentHeight - 24) + 32), - ], ), - ), + ), + child: Padding( + padding: const EdgeInsets.all(8), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ...widget.attributions.whereType(), + const TextSourceAttribution( + "Made with 'flutter_map'", + prependCopyright: false, + textStyle: TextStyle(fontStyle: FontStyle.italic), + ), + SizedBox(height: (widget.permanentHeight - 24) + 32), + ], ), ), ), - MouseRegion( - key: persistentAttributionKey, - onEnter: (_) => setState(() => persistentHovered = true), - onExit: (_) => setState(() => persistentHovered = false), - cursor: SystemMouseCursors.click, - child: AnimatedOpacity( - opacity: persistentHovered || popupExpanded ? 1 : 0.5, - curve: widget.animationConfig.buttonCurve, - duration: widget.animationConfig.buttonDuration, - child: Padding( - padding: const EdgeInsets.all(4), - child: FittedBox( - child: Row( - mainAxisSize: MainAxisSize.min, - children: - widget.alignment == AttributionAlignment.bottomLeft - ? persistentAttributionItems.reversed.toList() - : persistentAttributionItems, - ), + ), + ), + MouseRegion( + onEnter: (_) => setState(() => persistentHovered = true), + onExit: (_) => setState(() => persistentHovered = false), + cursor: SystemMouseCursors.click, + child: AnimatedOpacity( + opacity: persistentHovered || popupExpanded ? 1 : 0.5, + curve: widget.animationConfig.buttonCurve, + duration: widget.animationConfig.buttonDuration, + child: Padding( + padding: const EdgeInsets.all(4), + child: FittedBox( + child: Row( + mainAxisSize: MainAxisSize.min, + children: + widget.alignment == AttributionAlignment.bottomLeft + ? persistentAttributionItems.reversed.toList() + : persistentAttributionItems, ), ), ), ), - ], - ), + ), + ], ), ); }