Home > Back-end >  flutter) I want to use a listview to jump directly to a specific section
flutter) I want to use a listview to jump directly to a specific section

Time:11-06

enter image description here

As shown in the picture, I want to go directly to the corresponding list view when I press the button.

Instead of scrolling through the list, you can use the buttons to move left and right.

This is my current code.

As shown below, I am running a pageview called body (which changes briefly after using listview), and I know how to come out in order, but I don't know what to use to get it out of a specific number. Do you have a yes or another question?

          GestureDetector(
            onTap: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) => Choice821()),);
            },

2

class Choice821 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    QuestionController _controller = Get.put(QuestionController());
    return Scaffold(
      appBar: AppBar(
        title: Text('복습 시험', style: TextStyle(color: Colors.black, fontWeight:FontWeight.bold,fontSize: 20,),),
        centerTitle: true,
        elevation: 0,
      ),
      body: Body(),
    );
  }
}

2

child: PageView.builder(
  physics: NeverScrollableScrollPhysics(),
  controller: _questionController.pageController,
  onPageChanged: _questionController.updateTheQnNum,
  itemCount: _questionController.questions.length,
  itemBuilder: (context, index) => ayotube(
    question: _questionController.questions[index],
    id: _questionController.questionNumber.value,
  ),
),

CodePudding user response:

You can simply do this:

// jump to page index with animation

_questionController.pageController.animateToPage(index);

// or jump to page index without animation

_questionController.pageController.jumpToPage(index);
  • Related