方法 'Tap' 没有为类型 'TapScreen' 定义

问题描述

我是这个世界的新手,仍在学习,这对你来说可能很容易,但对我来说却不是:( 我正在对一个测试应用程序进行一些编码,但我被困在 TapBar 小部件上, 消息是: 方法 'Tap' 没有为类型 'TapScreen' 定义。 尝试将名称更正为现有方法名称,或定义名为“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