0

How do I make this section clickable so that I can navigate to another page, have a grid of pictures that I want to be able to navigate to and play videos from.

                  SizedBox(height: 30,),
                    Container(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text("Weight Loss Workouts", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.lime[700], fontSize: 25),),
                          SizedBox(height: 20,),
                          Container(
                            height: 200,
                            child: ListView(
                              scrollDirection: Axis.horizontal,
                              children: <Widget>[
                                makeItem(image: 'assets/images/dom4.jpg', title: 'Weight Loss Workout 1'),
                                makeItem(image: 'assets/images/weightloss.png', title: 'Weigth Loss Workout 2'),
                                makeItem(image: 'assets/images/dom4.jpg', title: 'Weight Loss Workout 3'),
                                makeItem(image: 'assets/images/weightloss.png', title: 'Weight Loss Workout 4'),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),

when I click on an image it would navigate to another page and play a video

  • This might help you: [https://stackoverflow.com/a/49959634/9342208](https://stackoverflow.com/a/49959634/9342208) – Bagghi Daku Apr 11 '20 at 15:09

2 Answers2

2

Wrap the Container inside InkWell and call navigation.push inside onTap callback function.

Sample code

 Container(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text("Weight Loss Workouts", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.lime[700], fontSize: 25),),
                          SizedBox(height: 20,),
                       InkWell(
                          onTap: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) => OrderDetailsPage(),
                              ),
                            );
                          },
                    child: Container(
                            height: 200,
                            child: ListView(
                              scrollDirection: Axis.horizontal,
                              children: <Widget>[
                                makeItem(image: 'assets/images/dom4.jpg', title: 'Weight Loss Workout 1'),
                                makeItem(image: 'assets/images/weightloss.png', title: 'Weigth Loss Workout 2'),
                                makeItem(image: 'assets/images/dom4.jpg', title: 'Weight Loss Workout 3'),
                                makeItem(image: 'assets/images/weightloss.png', title: 'Weight Loss Workout 4'),
                              ],
                            ),
                          ),
                         ),
                        ],
                      ),

)

Check more about https://api.flutter.dev/flutter/material/InkWell-class.html

Also check GestureDetector if you don't want touch feedback: https://api.flutter.dev/flutter/widgets/GestureDetector-class.html

Gaurav jain
  • 371
  • 1
  • 7
  • 13
1

GestureDetector( onTap: () => ......, child: Container(...), );

for Example

GestureDetector( onTap: () => print("container clicked"), child: Container(color:Colors.BLACK,width:100,height:100), );

RIYAS PULLUR
  • 13
  • 1
  • 4