Flutter ListTile onTap:()->;触发器错误:错误:不是常量表达式

Flutter ListTile onTap:()->;触发器错误:错误:不是常量表达式,flutter,Flutter,我的代码如下: drawer: Drawer( child: ListView( ... children: const <Widget>[ SizedBox( ... ), ListTile( leading: Icon(Icons.message), title: Text('Reportes de daños recibidos'), ***onTap: () {

我的代码如下:

drawer: Drawer(
  child: ListView(
    ...
    children: const <Widget>[

    SizedBox(
      ...
    ),

      ListTile(
        leading: Icon(Icons.message),
        title: Text('Reportes de daños recibidos'),
        ***onTap: () {
          Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => ReportsToDo()));
        },***
      ),
谢谢


Javier Caceres

我刚刚通过删除listview children属性的CONST关键字,在一个极小的应用程序中复制了您的代码,它工作得非常好。在这里检查

import 'package:flutter/material.dart';
import 'package:ui_learning/appScreen.dart';
void main() {
runApp(MaterialApp(
title: 'Flutter Tutorial',
home: TutorialHome(),
));
}

class TutorialHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Scaffold is a layout for the major Material Components.
return Scaffold(
  drawer: Drawer(
      child: ListView(children: <Widget>[
    SizedBox(
      height: 10,
    ),
    ListTile(
      leading: Icon(Icons.message),
      title: Text('Reportes de daños recibidos'),
      onTap: () {
        Navigator.push(
            context, MaterialPageRoute(builder: (context) => AppScreen()));
      },
    )
  ])),
  appBar: AppBar(
    leading: IconButton(
      icon: Icon(Icons.menu),
      tooltip: 'Navigation menu',
      onPressed: null,
    ),
    title: Text('Example title'),
    actions: <Widget>[
      IconButton(
        icon: Icon(Icons.search),
        tooltip: 'Search',
        onPressed: null,
      ),
    ],
  ),
  // body is the majority of the screen.
  body: Center(
    child: Text('Hello, world!'),
  ),
  floatingActionButton: FloatingActionButton(
    tooltip: 'Add', // used by assistive technologies
    child: Icon(Icons.add),
      onPressed: null,
     ),
  );
 }
 }
导入“包装:颤振/材料.省道”;
导入“包:ui_learning/appScreen.dart”;
void main(){
runApp(材料应用程序)(
标题:“颤振教程”,
主页:教程主页(),
));
}
类TutorialHome扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
//脚手架是主要材料组件的布局。
返回脚手架(
抽屉(
子项:列表视图(子项:[
大小盒子(
身高:10,
),
列表砖(
前导:图标(Icons.message),
标题:文本(“报告德达尼奥斯recibidos”),
onTap:(){
导航器。推(
context,MaterialPageRoute(builder:(context)=>AppScreen());
},
)
])),
appBar:appBar(
领先:IconButton(
图标:图标(图标菜单),
工具提示:“导航菜单”,
onPressed:null,
),
标题:文本(“示例标题”),
行动:[
图标按钮(
图标:图标(Icons.search),
工具提示:“搜索”,
onPressed:null,
),
],
),
//主体是屏幕的主体。
正文:中(
孩子:文本(“你好,世界!”),
),
浮动操作按钮:浮动操作按钮(
工具提示:“添加”,//由辅助技术使用
子:图标(Icons.add),
onPressed:null,
),
);
}
}

尝试删除
const
关键字已尝试过,但无效:(
import 'package:flutter/material.dart';
import 'package:ui_learning/appScreen.dart';
void main() {
runApp(MaterialApp(
title: 'Flutter Tutorial',
home: TutorialHome(),
));
}

class TutorialHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Scaffold is a layout for the major Material Components.
return Scaffold(
  drawer: Drawer(
      child: ListView(children: <Widget>[
    SizedBox(
      height: 10,
    ),
    ListTile(
      leading: Icon(Icons.message),
      title: Text('Reportes de daños recibidos'),
      onTap: () {
        Navigator.push(
            context, MaterialPageRoute(builder: (context) => AppScreen()));
      },
    )
  ])),
  appBar: AppBar(
    leading: IconButton(
      icon: Icon(Icons.menu),
      tooltip: 'Navigation menu',
      onPressed: null,
    ),
    title: Text('Example title'),
    actions: <Widget>[
      IconButton(
        icon: Icon(Icons.search),
        tooltip: 'Search',
        onPressed: null,
      ),
    ],
  ),
  // body is the majority of the screen.
  body: Center(
    child: Text('Hello, world!'),
  ),
  floatingActionButton: FloatingActionButton(
    tooltip: 'Add', // used by assistive technologies
    child: Icon(Icons.add),
      onPressed: null,
     ),
  );
 }
 }