我的抽屉内容:
drawer: Drawer(
elevation: 0.0,
child: Container(
color: kBackgroundColor,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.grey,
image: DecorationImage(
alignment: Alignment.topRight,
image: AssetImage('images/banner.png'),
fit: BoxFit.cover,
),
),
child: Text('App Test'),
),
ReusableOptionTile(
textData: 'Home',
icon: Icons.home,
onTouch: () {
print('Home Clicked');
Navigator.pop(context);
},
),
]
),
),
),
提取的列表磁贴内容:
class ReusableOptionTile extends StatelessWidget {
const ReusableOptionTile(
{required this.icon, required this.textData, required this.onTouch});
final IconData icon;
final String textData;
final Function onTouch;
@override
Widget build(BuildContext context) {
return ListTile(
title: Row(
children: [
Icon(icon),
SizedBox(
width: 5.0,
),
Text('$textData'),
],
),
onTap: onTouch, // ERROR POINT
);
}
}
我从 Drawer 中提取了 List Tile 以使代码更具可重用性,但现在无法为不同的 tile 传递 on tap 函数。在错误点显示错误“无法将参数类型'Function'分配给参数类型'void Function()?'。”
如何解决这个问题?