Flutter:我可以在 ListView 构建器中 enable/disable InkWell 吗?

Flutter: can I enable/disable InkWell in ListView builder?

我正在开发教育应用程序(类似于 udemy 应用程序) 在讲座列表屏幕中,我使用 Inkwell 显示讲座数据卡片,然后点击(当用户点击卡片时)它将转到视频播放页面

Lecture list page image HERE

加载讲座列表屏幕时: 首先,我有功能用 http.POST 检查每个讲座的观看次数 如果讲座观看次数少于 2 次我想让讲座卡片可以点击(用户可以多看一次讲座)

但如果用户的观看次数等于 2,我想停用该讲座,以防止用户再次观看

我想使用 if 语句检查观看次数然后启用 Inkwell onTap 属性 或不启用,但它不起作用

我需要有关如何处理这种情况的帮助

======================= 观看次数函数

checkViewsCount() async {
                        var XX = await checkLessonViews(lesson.id.toString(), lesson.lessonType);

                        if(int.parse(XX) >= 2){
                          //////////////////Here want to make lecture card disabled
                        } else {
                          //////////////////Here want to make lecture card enabled
                        }

                      }

============================ 这是 InkWell 代码

return InkWell(

                        onTap: () {
                          setState(() {
                            _activeLesson = lesson;
                          });
                          lessonAction(lesson);
                        },

                        child: Column(
                          children: <Widget>[
                            Container(
                              padding: EdgeInsets.symmetric(
                                  vertical: 10, horizontal: 30),
                              width: double.infinity,
                           child: Row(
                                children: <Widget>[
                                  //////////////////////// Lesson No.
                                  Expanded(
                                      flex: 2,
                                      child: Customtext(
                                        text: lessonCount.toString(),
                                        fontSize: 16
                                      )),
                                  //////////////////////// Lesson title
                                  Expanded(
                                      flex: 8,
                                      child: Column(
                                        crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                        children: <Widget>[
                                          Customtext(
                                            text: lesson.title,
                                            fontSize: 14,
                                            colors: kTextColor,
                                            fontWeight:
                                            FontWeight.bold,
                                          ),
                                          getLessonSubtitle(lesson),
                                        ],
                                      )),
                                ],
                              ),
                            ),
                            Divider(),
                          ],
                        ),
                      );

提前致谢

您不能在 flutter 中禁用 inkwell,使用 if 条件根据用户拥有的视图数显示 inkwell 或容器(没有手势处理属性)。

var canAddLecture = true;

if(int.parse(XX) >= 2){
  canAddLecture = false;
} else {
  canAddLecture = true;
}

并在 onTap 中:

onTap: () {
   if(canAddLecture == false) return;
   setState(() {
       _activeLesson = lesson;
   });
   lessonAction(lesson);
}