Flutter 请求的导航器操作的上下文不包括导航器-颤振
我的颤振文件中的导航器有问题 问题出现在Flutter 请求的导航器操作的上下文不包括导航器-颤振,flutter,navigator,Flutter,Navigator,我的颤振文件中的导航器有问题 问题出现在\u listItem中的我的手势检测器中,点击对象后,在我的调试控制台中抛出我: 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 th
\u listItem
中的我的手势检测器中,点击对象后,在我的调试控制台中抛出我:
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.
我不知道为什么这对我不起作用,有人能帮我吗
下面是我的代码:
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home:Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child: AppBar(
iconTheme: IconThemeData(color: Color.fromRGBO(9, 133, 46, 100)),
backgroundColor: Colors.white,
actions: <Widget>[
IconButton(
icon: Icon(
Icons.shopping_cart,
color: Color.fromRGBO(9, 133, 46, 100),
),
onPressed: (){
print('klikniete');
},
),
],
),
),
body: Builder(
builder: (context) => Container(
child: FutureBuilder(
future: fetchOrders(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (_ordersForDisplay.length == null) {
return Container(
child: Center(child: Text("Ładowanie...")),
);
} else {
return ListView.builder(
itemCount: _ordersForDisplay.length + 1,
itemBuilder: (BuildContext context, int index) {
return index == 0 ? _searchBar() : _listItem(index - 1);
},
);
}
},
),
),
),
)
);
}
_listItem(index) {
return GestureDetector(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(builder: (context) => DetailPage(item: _ordersForDisplay[index])),
),
child: Card(
child: Padding(
padding: const EdgeInsets.only(
top: 32.0, bottom: 32.0, left: 16.0, right: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_ordersForDisplay[index].firstName,
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
Text(
_ordersForDisplay[index].lastName,
style: TextStyle(
color: Colors.grey.shade600
),
),
],
),
),
),
);
}
}
class DetailPage extends StatelessWidget {
final Order item;
const DetailPage({this.item});
@override
Widget build(BuildContext context) {
return Center(
child: Text('${item.firstName} - ${item.lastName}')
);
}
}
class\u HomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:首选大小(
首选尺寸:尺寸。从高度(100.0),
孩子:AppBar(
iconTheme:IconThemeData(颜色:color.fromRGBO(913346100)),
背景颜色:Colors.white,
行动:[
图标按钮(
图标:图标(
图标。购物车,
颜色:颜色。来自RGBO(913346100),
),
已按下:(){
印刷品(“klikniete”);
},
),
],
),
),
车身:建造商(
生成器:(上下文)=>容器(
孩子:未来建设者(
future:fetchOrders(),
生成器:(BuildContext上下文,异步快照){
if(_ordersForDisplay.length==null){
返回容器(
子对象:中心(子对象:文本(“Ładowanie…”)),
);
}否则{
返回ListView.builder(
itemCount:_ordersForDisplay.length+1,
itemBuilder:(构建上下文,int索引){
返回索引==0?\u搜索栏():\u列表项(索引-1);
},
);
}
},
),
),
),
)
);
}
_列表项(索引){
返回手势检测器(
onTap:()=>Navigator.of(context.push)(
MaterialPage路线(生成器:(上下文)=>DetailPage(项目:_ordersForDisplay[索引]),
),
孩子:卡片(
孩子:填充(
填充:仅限常量边设置(
顶部:32.0,底部:32.0,左侧:16.0,右侧:16.0),
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
正文(
_ordersForDisplay[index].firstName,
样式:TextStyle(fontSize:22,fontWeight:fontWeight.bold),
),
正文(
_ordersForDisplay[index].lastName,
样式:TextStyle(
颜色:Colors.grey.shade600
),
),
],
),
),
),
);
}
}
类DetailPage扩展了无状态小部件{
最终订单项目;
const DetailPage({this.item});
@凌驾
小部件构建(构建上下文){
返回中心(
子项:文本(“${item.firstName}-${item.lastName}”)
);
}
}
尝试将方法参数更改为
_listItem(index, context) { //Changes here
....
}
并将上下文传递到您调用它的位置
return index == 0 ? _searchBar() : _listItem(index - 1,context);
这回答了你的问题吗@冥想,我看到了这个主题并检查了它,但没有任何帮助。你能告诉我如何将我的搜索栏放入应用程序栏吗?我仍然尝试这样做,但没有成功:(现在,他在应用程序栏下,但我希望他能在应用程序栏中找到,最好是在最底部