Search code examples
flutterdartgesturedetector

How to have multiple child with their onTaps within GestureDetector?


I have a sign-up page which contains Text like privacy policy, terms and etc and I want that on clicking those text webpage should get open. I used the GestureDetector for that but the issue is that it contains one child only

But I want all the three texts to be there and should perform Onclick or here onTap.

Any idea?

          GestureDetector(
                onTap: () => launch(
                    'https://docs.flutter.io/flutter/services/UrlLauncher-        class.html'),
                child: Text('Terms of use,',
                    style: TextStyle(
                        color: Colors.blueAccent,
                        fontSize: 18.0,
                        fontWeight: FontWeight.bold)),
              )           

expected: all three text with onTap inside GestureDetector. actual: only one child is there.


Solution

  • You can try creating a Row widget which contains the text you need, that is, privacy policy, terms and etc, as its children. And then wrap the Text widgets with GestureDetector widgets. A code snippet is given below:

    Container(
            alignment: Alignment.center,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                GestureDetector(
                  onTap: (){
                    print("Privacy policy");
                  },
                  child: Text("Privacy policy, "),
                ),
                GestureDetector(
                  onTap: (){
                    print('Terms');
                  },
                  child: Text("Terms, "),
                ),
                GestureDetector(
                  onTap: (){
                    print('Contact Us');
                  },
                  child: Text("Contact Us"),
                ),
              ],
            ),
          ),
    

    Outputs:

    enter image description here

    enter image description here

    Hope this helps!!