Schwusch / widget_arrows

Draw arrows between widgets in Flutter
https://pub.dev/packages/widget_arrows
MIT License
145 stars 14 forks source link

Bad state: No element #6

Closed helenxuyang closed 1 year ago

helenxuyang commented 4 years ago

Hi, I'm getting a "Bad state: no element" error coming from the line final lastPathMetric = path.computeMetrics().last; inside of ArrowPainter's paint method.

I'm trying to put an arrow between two Column widgets with this format:

             ArrowContainer(
                  child: Row(
                      children: [
                        Container(
                          width: MediaQuery.of(context).size.width / 2,
                          child: ArrowElement(
                            color: Colors.black,
                            id: 'left',
                            targetId: 'right',
                            sourceAnchor: Alignment.centerRight,
                            targetAnchor: Alignment.centerLeft,
                            child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  // text widgets
                                ]
                            ),
                          ),
                        ),
                        ArrowElement(
                          id: 'right',
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                               // text widgets
                              )
                            ],
                          ),
                        )
                      ]
                  ),
                ),

I'm not very familiar with painting so I'm not quite sure what's going on. Any help would be appreciated, thank you!

Full error message:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ The following StateError was thrown during paint(): Bad state: No element

The relevant error-causing widget was: ArrowContainer file:///C:/Users/85hal/Documents/Projects/carriage-driver/lib/Ride.dart:63:20

When the exception was thrown, this was the stack:

0 Iterable.last (dart:core/iterable.dart:542:7)

1 _ArrowPainter.paint. (package:widget_arrows/widget_arrows.dart:139:54)

2 Iterable.forEach (dart:core/iterable.dart:283:30)

3 _ArrowPainter.paint (package:widget_arrows/widget_arrows.dart:74:60)

4 RenderCustomPaint._paintWithPainter (package:flutter/src/rendering/custom_paint.dart:533:13)

5 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:579:7)

6 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

7 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

8 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

9 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

10 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

11 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2525:15)

12 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:608:5)

13 RenderStack.paint (package:flutter/src/rendering/stack.dart:616:7)

14 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

15 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

16 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:72:15)

17 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

18 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

19 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

20 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

21 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

22 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

23 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:533:11)

24 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

25 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

26 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

27 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:577:11)

28 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

29 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

30 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

31 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:393:12)

32 RenderPhysicalShape.paint (package:flutter/src/rendering/proxy_box.dart:1920:15)

33 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

34 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

35 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:72:15)

36 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

37 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

38 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

39 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

40 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:186:13)

41 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:133:15)

42 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2266:7)

43 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:137:11)

44 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:97:5)

45 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:982:29)

46 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:406:19)

47 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:867:13)

48 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)

49 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)

50 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)

51 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5)

55 _invoke (dart:ui/hooks.dart:253:10)

56 _drawFrame (dart:ui/hooks.dart:211:3)

(elided 3 frames from dart:async)

The following RenderObject was being processed when the exception was fired: RenderCustomPaint#3051c relayoutBoundary=up27: creator: CustomPaint ← IgnorePointer ← Stack ← ArrowContainer ← Padding ← Semantics ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ea354 ink renderer] ← NotificationListener ← CustomPaint ← _ShapeBorderPaint ← ⋯ parentData: (can use size) constraints: BoxConstraints(0.0<=w<=288.0, 0.0<=h<=Infinity) size: Size(288.0, 0.0) This RenderObject had the following descendants (showing up to depth 5): child: RenderLimitedBox#de2b9 relayoutBoundary=up28 child: RenderConstrainedBox#c63ac relayoutBoundary=up29 ════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════ The following StateError was thrown during paint(): Bad state: No element

The relevant error-causing widget was: ArrowContainer file:///C:/Users/85hal/Documents/Projects/carriage-driver/lib/Ride.dart:63:20 When the exception was thrown, this was the stack:

0 Iterable.last (dart:core/iterable.dart:542:7)

1 _ArrowPainter.paint. (package:widget_arrows/widget_arrows.dart:139:54)

2 Iterable.forEach (dart:core/iterable.dart:283:30)

3 _ArrowPainter.paint (package:widget_arrows/widget_arrows.dart:74:60)

4 RenderCustomPaint._paintWithPainter (package:flutter/src/rendering/custom_paint.dart:533:13)

... The following RenderObject was being processed when the exception was fired: RenderCustomPaint#3051c relayoutBoundary=up27 ... parentData: (can use size) ... constraints: BoxConstraints(0.0<=w<=288.0, 0.0<=h<=Infinity) ... size: Size(288.0, 0.0) RenderObject: RenderCustomPaint#3051c relayoutBoundary=up27 parentData: (can use size) constraints: BoxConstraints(0.0<=w<=288.0, 0.0<=h<=Infinity) size: Size(288.0, 0.0) ... child: RenderLimitedBox#de2b9 relayoutBoundary=up28 ... parentData: (can use size) ... constraints: BoxConstraints(0.0<=w<=288.0, 0.0<=h<=Infinity) ... size: Size(288.0, 0.0) ... maxWidth: 0.0 ... maxHeight: 0.0 ... child: RenderConstrainedBox#c63ac relayoutBoundary=up29 ... parentData: (can use size) ... constraints: BoxConstraints(0.0<=w<=288.0, h=0.0) ... size: Size(288.0, 0.0) ... additionalConstraints: BoxConstraints(biggest) ════════════════════════════════════════════════════════════════════════════════════════════════════