我在onTap中遇到错误。错误:参数类型“Function”不能分配给参数类型“void Function()?”。
- “函数”来自“dart:core”。onTap:点击
import 'package:flutter/material.dart';
import '../users_list/models/users_list_model.dart';
import 'app_title.dart';
class UserListRow extends StatelessWidget {
final UserModel userModel;
final Function onTap;
UserListRow({required this.userModel, required this.onTap});
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppTitle(text: userModel.name),
Text(
userModel.email,
style: TextStyle(color: Colors.black),
),
],
),
),
);
}
}
1条答案
按热度按时间wgeznvg71#
在Function后面加上括号,将上面提到的代码更改为: