Giter Club home page Giter Club logo

Comments (7)

rrousselGit avatar rrousselGit commented on May 24, 2024

I don't think you pointed to the right assert. This one is for when you changed the type of the hook.

The issue you described is the following assert: https://github.com/rrousselGit/flutter_hooks/blob/master/lib/src/framework.dart#L124

which clearly states

Hook.use can only be called from the build method of HookWidget

from flutter_hooks.

rrousselGit avatar rrousselGit commented on May 24, 2024

I would love to add in the message the name of the class who used it. But it is technically not possible since this issue happens when hooks don't know which class called Hook.use

The most you can get out of this is by looking at the stacktrace, which should contain the name of the caller.

from flutter_hooks.

lucasavila00 avatar lucasavila00 commented on May 24, 2024

@rrousselGit, that's not the case.
I'm using v0.2.0 and changed a HookWidget to StatelessWidget and got this on the stacktrace.

I/flutter (22968): 'package:flutter_hooks/src/framework.dart': Failed assertion: line 354 pos 14:
I/flutter (22968): '_currentHook.current?.hook?.runtimeType == hook.runtimeType': is not true.
I/flutter (22968):
I/flutter (22968): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (22968): more information in this error message to help you determine and fix the underlying cause.
I/flutter (22968): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (22968):   https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (22968):
I/flutter (22968): When the exception was thrown, this was the stack:
I/flutter (22968): #2      HookElement._use (package:flutter_hooks/src/framework.dart:354:14)
I/flutter (22968): #3      Hook.use (package:flutter_hooks/src/framework.dart:129:40)
I/flutter (22968): #4      useState (package:flutter_hooks/src/hooks.dart:205:15)
I/flutter (22968): #5      _EditingKmBar.build (package:mob/searchpage/view.dart:129:17)
I/flutter (22968): #6      StatelessElement.build (package:flutter/src/widgets/framework.dart:3774:28)
I/flutter (22968): #7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
I/flutter (22968): #8      Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22968): #9      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22968): #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22968): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22968): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22968): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22968): #14     HookElement.performRebuild (package:flutter_hooks/src/framework.dart:258:11)
I/flutter (22968): #15     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22968): #16     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
I/flutter (22968): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
I/flutter (22968): #18     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (22968): #19     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (22968): #20     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (22968): #21     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (22968): #22     _invoke (dart:ui/hooks.dart:154:13)
I/flutter (22968): #23     _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter (22968): (elided 2 frames from class _AssertionError)

Maybe the assertion I linked above is being triggered before the one with the correct message...

Thanks for the attention 👍

from flutter_hooks.

rrousselGit avatar rrousselGit commented on May 24, 2024

Can you provide a minimal example to reproduce this error?

When I do the same thing, I get a

type MyWidget is not a subtype of HookWidget in typecast

from flutter_hooks.

rrousselGit avatar rrousselGit commented on May 24, 2024

@degroote22 Any update on this issue? I cannot progress on this without being able to reproduce the error

from flutter_hooks.

lucasavila00 avatar lucasavila00 commented on May 24, 2024

I'm sorry for the delay. I'd taken some time off celebrating the new year :)

I'll provide you with a reproduction tomorrow!

from flutter_hooks.

lucasavila00 avatar lucasavila00 commented on May 24, 2024

I'm trying to reproduce with 0.2.1 and it won't happen anymore 👍
I'm closing this, and once again, I'm sorry for the delay.

But, if you were interested on the issue, it would only happen when hot reloading. When hot restarting the proper error would be shown.

from flutter_hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.