Comments (7)
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.
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.
@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.
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 ofHookWidget
in typecast
from flutter_hooks.
@degroote22 Any update on this issue? I cannot progress on this without being able to reproduce the error
from flutter_hooks.
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.
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)
- [BUG] shouldPreserveState may wrongfully preserve state when it shouldn't HOT 1
- Feature Request: `useListener` hook HOT 3
- about the useMemoized API description
- Add useSound Hook HOT 2
- flutter_hooks: ^0.20.3 HOT 2
- Add hook to observe `didChangeDependencies`
- Why list not updating? HOT 7
- EditText reverting to previous value HOT 2
- Implement useTabControllerList for List<TabController> HOT 6
- Clarify usage of useFuture through documentation HOT 1
- Inconsistency in AppLifecycleState Detection Between iOS and Android in Flutter Hooks HOT 5
- Possibility of deprecating useIsMounted HOT 2
- `when` for `AsyncSnapshot` HOT 1
- Assertion Error with useExpansionTileController HOT 5
- a hook for the DraggableScrollableController HOT 2
- Using useFuture and useStream keeps invoking the widget build method unnecessarily. HOT 5
- Setting TextEditingController.text selects input in TextField in Web HOT 1
- onAttach and onDetach is missing on usePageController
- ERROR: Undefined class 'WidgetStatesController'. HOT 4
- [Feature Request] Is it possible to implement `useSWR` in flutter_hooks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_hooks.