Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LateInitializationError: Field '_controller@1501137672' has already been  initialized #45

Closed
AtixD opened this issue Dec 14, 2021 · 3 comments

Comments

@AtixD
Copy link

AtixD commented Dec 14, 2021

Hi, I have error when I try create a new justTheController
Any ideas?

StackTrace: #0      LateError._
throwFieldAlreadyInitialized (dart:_internal-patch\/internal_patch.dart:211)\n#1      _JustTheToolt
ipState._controller= (package:just_the_tooltip\/src\/just_the_tooltip.dart:150)\n#2      _JustTheTo
oltipState.didUpdateWidget (package:just_the_tooltip\/src\/just_the_tooltip.dart:222)\n#3      Stat
efulElement.update (package:flutter\/src\/widgets\/framework.dart:4855)\n#4      Element.updateChil
d (package:flutter\/src\/widgets\/framework.dart:3412)\n#5      ComponentElement.performRebuild (pa
ckage:flutter\/src\/widgets\/framework.dart:4690)\n#6      Element.rebuild (package:flutter\/src\/w
idgets\/framework.dart:4355)\n#7      StatelessElement.update (package:flutter\/src\/widgets\/frame
work.dart:4746)\n#8      Element.updateChild (package:flutter\/src\/widgets\/framework.dart:3412)\n
#9      ComponentElement.performRebuild (package:flutter\/src\/widgets\/framework.dart:4690)\n#10
   StatefulElement.performRebuild (package:flutter\/src\/widgets\/framework.dart:4840)\n#11     Ele
ment.rebuild (package:flutter\/src\/widgets\/framework.dart:4355)\n#12     StatefulElement.update (
package:flutter\/src\/widgets\/framework.dart:4872)\n#13     Element.updateChild (package:flutter\/
src\/widgets\/framework.dart:3412)\n#14     Element.inflateWidget (package:flutter\/src\/widgets\/f
ramework.dart:3663)\n#15     Element.updateChild (package:flutter\/src\/widgets\/framework.dart:342
5)\n#16     ComponentElement.performRebuild (package:flutter\/src\/widgets\/framework.dart:4690)\n#
17     StatefulElement.performRebuild (package:flutter\/src\/widgets\/framework.dart:4840)\n#18
 Element.rebuild (package:flutter\/src\/widgets\/framework.dart:4355)\n#19     ComponentElement._fi
rstBuild (package:flutter\/src\/widgets\/framework.dart:4643)\n#20     StatefulElement._firstBuild
(package:flutter\/src\/widgets\/framework.dart:4831)\n#21     ComponentElement.mount (package:flutt
er\/src\/widgets\/framework.dart:4638)\n#22     Element.inflateWidget (package:flutter\/src\/widget
s\/framework.dart:3673)\n#23     Element.updateChild (package:flutter\/src\/widgets\/framework.dart
:3425)\n#24     ComponentElement.performRebuild (package:flutter\/src\/widgets\/framework.dart:4690
...
#201    BuildOwner.buildScope (package:flutter\/src\/widgets\/framework.dart:2620)\n#202    Widgets
Binding.drawFrame (package:flutter\/src\/widgets\/binding.dart:882)\n#203    RendererBinding._handl
ePersistentFrameCallback (package:flutter\/src\/rendering\/binding.dart:319)\n#204    SchedulerBind
ing._invokeFrameCallback (package:flutter\/src\/scheduler\/binding.dart:1143)\n#205    SchedulerBin
ding.handleDrawFrame (package:flutter\/src\/scheduler\/binding.dart:1080)\n#206    SchedulerBinding
._handleDrawFrame (package:flutter\/src\/scheduler\/binding.dart:996)\n#207    _rootRun (dart:async
\/zone.dart:1428)\n#208    _CustomZone.run (dart:async\/zone.dart:1328)\n#209    _CustomZone.runGua
rded (dart:async\/zone.dart:1236)\n#210    _invoke (dart:ui\/hooks.dart:166)\n#211    PlatformDispa
tcher._drawFrame (dart:ui\/platform_dispatcher.dart:270)\n#212    _drawFrame (dart:ui\/hooks.dart:1
29)\n \n\n Error message: LateInitializationError: Field '_controller@1501137672' has already been 
initialized
@stargazing-dino
Copy link
Owner

I haven't personally run into this but I think you're triggering a rebuild which triggers this line

https://github.com/Nolence/just_the_tooltip/blob/7fa3df1a54d273c1f224c8c1d14e5cac426bdc1e/lib/src/just_the_tooltip.dart#L374

which then calls this:

https://github.com/Nolence/just_the_tooltip/blob/7fa3df1a54d273c1f224c8c1d14e5cac426bdc1e/lib/src/models/just_the_controller.dart#L30

and sets the values of the appropriate callbacks.

I'm not totally sure about late fields but I thought their values could be set at any time (after their first initialization) so long as they weren't marked final? I'm assuming that's what that late initialization error means?

If you could provide steps to reproduce I can revisit this later

@stargazing-dino
Copy link
Owner

nope, I found the actual issue. I misread that stack trace and assumed it was the controller's field that were being reinitiatlized but its actually the controller itself. On trigger of widget rebuild and if there's a new controller value passed to JustTheTooltip then we'll end up here

https://github.com/Nolence/just_the_tooltip/blob/7fa3df1a54d273c1f224c8c1d14e5cac426bdc1e/lib/src/just_the_tooltip.dart#L361

which will set the value of the controller to a new value which will error because it's a late final.

Solution is probably to just remove final keyword

@stargazing-dino
Copy link
Owner

Try 0.0.11+1 which just removes final keyword

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants