flutter - 在颤动的卡片小部件内添加一个凸起的按钮
问题描述
我有这个底部导航栏项目,它有卡片作为它的列小部件子项。我试图将卡片内的凸起按钮作为尾随属性传递,但 onPressed() 函数在初始化时出错。它说“无效的常数值”。
List _widgetOptions = <Widget>[
Scaffold(
appBar: AppBar(
title: Text("Fines"),
),
body: Container(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const ListTile(
title: Text('Fine ID: 3265'),
subtitle: Text('Fines: Crossing double line\novertaking on pedestrian crossing'),
trailing: RaisedButton(
onPressed: () {},//**this line is underlined in red. Error is here**
color: Colors.green,
child: Text('Pay'),
),
),
],
),
)
],
),
),
)),
];
解决方案
问题是在树中有 RaisedButton 时尝试使用 const 构造ListTile,只需在ListTile解决问题之前删除const关键字即可。
如果你想使用const,你可以这样做:
import 'package:flutter/material.dart';
void main() {
return runApp(
MaterialApp(
home: Scaffold(
body: TestPage(),
),
),
);
}
class TestPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: ListTile(
title: const Text('Fine ID: 3265'),
subtitle: const Text(
'Fines: Crossing double line\novertaking on pedestrian crossing'),
trailing: RaisedButton(
onPressed: () {}, //**this line is underlined in red. Error is here**
color: Colors.green,
child: const Text('Pay'),
),
),
);
}
}
推荐阅读
- sql - 如何通过将持续时间添加到开始日期 SQL 来更新结束日期
- mosquitto - 有多少用户可以接受 mosquitto 用户列表?
- robotframework - Robot Framework 中的无头测试
- python-3.x - 将 python 2 转换为 python 3('PROCESS_ALL_ACCESS' 未定义)
- hibernate - 如何在 SELECT 查询中制作休眠前缀 N?
- asp.net-mvc - 用控件填写表单(根据服务返回的数据)
- excel - 创建具有多个工作条件的 IF 语句
- ios - 如何用渐变颜色的控制点填充贝塞尔路径
- python - Python - Intcheck 函数不起作用
- windows - PNRP 停止工作窗口 10 1803