简体   繁体   中英

How to make words inside a paragraph clickable in flutter?

I have a line that has three buttons inside it. I know that I can use RichText with Gesture Recogniser to make them clickable like HTML <a href=""> tag. But I am new to flutter and don't know how can I achieve that behaviour.

Also is there any better option to do similar thing?

Also I don't want to open an External Link. Just navigate to another page.

I have attached a picture containing what I want to do. Picture of what I want to do

import 'package:flutter/gestures.dart';

and the widget

 RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: "By Clicking Sign up you are agree to the ",
            ),
            TextSpan(
              text: "Privacy Policy ",
              style: TextStyle(
                color: Colors.lightGreen,
              ),
              recognizer: new TapGestureRecognizer()
                ..onTap = () => print("Privacy Policy"),
            ),
            TextSpan(text: "and our "),
            TextSpan(
              text: "Terms and Conditions ",
              style: TextStyle(
                color: Colors.lightGreen,
              ),
              recognizer: new TapGestureRecognizer()
                ..onTap = () => print("Terms and Conditions"),
            ),
            TextSpan(text: "and "),
            TextSpan(
              text: "Cookie Statement",
              style: TextStyle(
                color: Colors.lightGreen,
              ),
              recognizer: new TapGestureRecognizer()
                ..onTap = () => print("Cookie Statement"),
            ),
            TextSpan(text: "."),
          ],
        ),
      ),

does it help?

you can wrap the Text widget with GestureDetector()

GestureDetector(
              child: Text(
                'Clickable text'
              ),
              onTap: () {
                //go to destination page
              },
            )

In case if you're opening to an external link you can check URL launcher to open websites

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM