flutter - 没有为类型“TapScreen”定义方法“Tap”
问题描述
我是这个世界的新手,还在学习,这对你来说可能很容易,但它不适合我:(我正在对一个测试应用程序进行一些编码,但我卡在了 TapBar 小部件上,消息是:方法'没有为类型“TapScreen”定义 Tap。尝试将名称更正为现有方法的名称,或定义名为“Tap”的方法。dartundefined_method
class TapScreen extends StatelessWidget {
const TapScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: <Widget>[
Tap ( <===// The problem is here on (Tap).
icon: Icon(Icons.dashboard),
text: 'Skills',
),
Tap( <===// The problem is here on (Tap).
icon: Icon(Icons.star),
text: 'Favorites',
),
],
),
),
body: TabBarView(
children: [
CategoriesScreen(),
FavoritesScreen(),
],
),
),
);
}
}
解决方案
问题是没有在您的文件中导入,或者小部件不存在,
如果您需要识别点击手势的小部件,请尝试 InkWell 或 GestureDetector 小部件
GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: YourCustomWidget()
)
同样的代码应该适用于 InkWell
推荐阅读
- sql - 我有一个包含每月数据的表。如何使用从该表中选择查询来平均每个季度的数据
- sql - 我收到“子查询返回超过 1 个值”,但我的 SELECT 上没有子查询
- terminal - 如何解决在本机脚本中锁定 user.settings 的超时问题?
- excel - 如何使用“查找”作为第一行和最后一行来查看值、匹配值并将相邻单元格复制到另一个工作簿?
- java - java - 如何在基于类的注释中声明事务bean?
- swift - 无需使用 inout 进行缓存的 Swift 动态编程
- sql - MariaDB 结果集未返回正确结果
- java - Spring boot JPA Hibernate 返回嵌套的 Json 对象:Reddit 风格的评论系统
- sqlite - 编程时sqlite和mysql有区别吗
- python - Python os.path.dirname("path") 错误 - 当路径以“/”终止时不返回父目录