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

Time:10-14

I working on education app (Something like udemy app) In lecture list screen, I use Inkwell to show lecture data card, and onTap (when user click on card) it will go to video player page

Lecture list page image HERE

When lecture list screen loaded: First I have function to check number of views with http.POST for every lecture If lecture views less than 2 views I want to make lecture card clickable (user can view lecture one more time)

but if user has views number equal 2 I want to disable the lecture, to prevent user to make another view

I think to use if statement to check number of views then enable Inkwell onTap property or not, but it's doesn't work

I need help about how I can do this situation

======================= views count function

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
                        }

                      }

============================ and this is InkWell code

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(),
                          ],
                        ),
                      );

Thanks in advance

CodePudding user response:

You can't disable inkwell in flutter, use an if condition to either display an inkwell or a container (without gesture handling properties) depending on the number of views the user has.

CodePudding user response:

var canAddLecture = true;

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

and in onTap:

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