当前位置:网站首页>[error record] navigator operation requested with a context that does not include a naviga
[error record] navigator operation requested with a context that does not include a naviga
2022-07-03 01:40:00 【Programmer community】
One 、 Error message
Flutter When the interface jumps , Report the following error :
======== Exception caught by gesture ===============================================================The following assertion was thrown while handling a gesture:Navigator operation requested with a context that does not include a Navigator.The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.When the exception was thrown, this was the stack: #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:2711:9)#1 Navigator.of (package:flutter/src/widgets/navigator.dart:2718:6)#2 HeroAnimation.build.<anonymous closure> (package:flutter_animation/main.dart:57:25)#3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:994:20)#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)...Handler: "onTap"Recognizer: TapGestureRecognizer#68181 debugOwner: GestureDetector state: possible won arena finalPosition: Offset(216.4, 420.6) finalLocalPosition: Offset(160.7, 193.9) button: 1 sent tap down====================================================================================================
Error code :
void main() {
runApp( HeroAnimation() );}class HeroAnimation extends StatelessWidget{
@override Widget build(BuildContext context) {
// Time expansion coefficient , Used to reduce the running speed of animation timeDilation = 10.0; return MaterialApp( home: Scaffold( body: Container( child: HeroWidget( imageUrl: "https://img-blog.csdnimg.cn/20210329101628636.jpg", width: 300, // Click event , Click this component here , Jump to a new page onTap: (){
print(" Click event trigger "); Navigator.of(context).push( MaterialPageRoute( builder: (context){
/// Jump to the new interface and define here return MaterialApp( home: Scaffold( body: Container( color: Colors.white, padding: EdgeInsets.all(20), alignment: Alignment.topLeft, child: HeroWidget( imageUrl: "https://img-blog.csdnimg.cn/20210329101628636.jpg", width: 100, onTap: (){
/// Exit the current interface Navigator.of(context).pop(); }, ), ), ), ); } ) ); }, ), ), ), ); }}Two 、 Problem analysis
Navigator operation requested with a context that does not include a Navigator.This error has nothing to do with the target interface of the jump , Only related to the current interface ;
The [MaterialApp] configures the top-level [Navigator] to search for routesin the following order: 1. For the `/` route, the [home] property, if non-null, is used. 2. Otherwise, the [routes] table is used, if it has an entry for the route. 3. Otherwise, [onGenerateRoute] is called, if provided. It should return a non-null value for any _valid_ route not handled by [home] and [routes]. 4. Finally if all else fails [onUnknownRoute] is called.If a [Navigator] is created, at least one of these options must handle the`/` route, since it is used when an invalid [initialRoute] is specified onstartup (e.g. by another application launching this one with an intent onAndroid; see [dart:ui.PlatformDispatcher.defaultRouteName]).This widget also configures the observer of the top-level [Navigator] (ifany) to perform [Hero] animations.If [home], [routes], [onGenerateRoute], and [onUnknownRoute] are all null,and [builder] is not null, then no [Navigator] is created.It's on it MaterialApp Notes , MaterialApp Will automatically create a Navigator , Here we use MaterialApp The above error is still reported ;
Navigator Search mechanism : This is due to calling Navigator.of(context) Code acquisition Navigator , Notice the context Context related is StatelessWidget Components , That is, the number should be StatelessWidget Component start , Upward search Navigator ;
But the actual level is like this , StatelessWidget The parcel MaterialApp The parcel Scaffold The parcel Container , lookup Navigator when , Over MaterialApp , Directly from the top StatelessWidget The component starts to look up , I'm sure I can't find Navigator , There is a direct error here ;
This is because Navigator Error caused by the search mechanism of , It's easy to solve this problem , stay StatelessWidget The outer layer of is wrapped with another MaterialApp , That would solve the problem ;
3、 ... and 、 Solution
stay main.dart Medium main() Function , Use MaterialApp Package interface jump components ;
In this way StatelessWidget The outer layer of the component is wrapped with another layer MaterialApp , So from StatelessWidget The component starts to look up Navigator , You can find it Navigator , Problem solving ;
void main() {
runApp( MaterialApp( title: "Hero Animation ", home: HeroAnimation(), ) );}边栏推荐
- [FPGA tutorial case 5] ROM design and Implementation Based on vivado core
- What operations need attention in the spot gold investment market?
- Tp6 fast installation uses mongodb to add, delete, modify and check
- Detailed explanation of Q-learning examples of reinforcement learning
- Vim 9.0正式发布!新版脚本执行速度最高提升100倍
- Is there a handling charge for spot gold investment
- word插入公式/endnote
- 【面试题】1369- 什么时候不能使用箭头函数?
- CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
- 网络安全-最简单的病毒
猜你喜欢

7-25 read numbers (loop switch)
![[data mining] task 2: mimic-iii data processing of medical database](/img/ad/4e7b253d60b29351e3ef252ee5230f.png)
[data mining] task 2: mimic-iii data processing of medical database

C#应用程序界面开发基础——窗体控制(2)——MDI窗体

STM32 - introduction of external interrupts exti and NVIC

C#应用程序界面开发基础——窗体控制(3)——文件类控件

什么是调。调的故事
![[fh-gfsk] fh-gfsk signal analysis and blind demodulation research](/img/8a/8ca80f51a03341c982d52980c54b01.png)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research

Pytest learning notes (12) -allure feature · @allure Step () and allure attach

QTableWidget懒加载剩内存,不卡!

给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
随机推荐
PS去除水印详解
C application interface development foundation - form control (1) - form form
Common English Vocabulary
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
Tâche 6: regroupement DBSCAN
网络安全-木马
数学知识:能被整除的数—容斥原理
Summary of interval knowledge
[androd] module dependency replacement of gradle's usage skills
[shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
Telecom Customer Churn Prediction challenge
Wireshark data analysis and forensics a.pacapng
[self management] time, energy and habit management
串口抓包/截断工具的安装及使用详解
[untitled]
Mathematical knowledge: step Nim game game game theory
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
STM32 - GPIO input / output mode
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?