简体   繁体   English

如何在 Flutter 上创建从 CheckboxlistTile 到另一个页面的“链接”

[英]How to make a "link" from CheckboxlistTile to another page on Flutter

I'm making a Terms and Conditions agreement and I want this sentence to be highlighted and clickable, when clicked it should take the user to another page in the app where they can read the agreement.我正在制定条款和条件协议,我希望突出显示并可点击这句话,点击后应该将用户带到应用程序中的另一个页面,他们可以在其中阅读协议。 I'm having trouble creating something that's both clickable and highlighted.我在创建既可点击又突出显示的内容时遇到问题。

Here is my code:这是我的代码:

 CheckboxListTile(
        value: checkboxValue,
      onChanged: (val) {
        if (checkboxValue == false) {
          setState(() {
            checkboxValue = true;
          });
        } else if (checkboxValue == true) {
          setState(() {
            checkboxValue = false;
          });
        }
      },
      subtitle: !checkboxValue
          ? Text(
              'Required.',
              style: TextStyle(color: Colors.red),
            )
          : null,
      title: new Text(
        'I agree to the Terms and Conditions.',
        style: TextStyle(fontSize: 14.0),
      ),
      controlAffinity: ListTileControlAffinity.leading,
      activeColor: Colors.green,
    ),
    ```

Wrap your Text widget with a GestureDetector() .GestureDetector()包装您的 Text 小部件。 See code below见下面的代码

CheckboxListTile(
                value: checkboxValue,
                onChanged: (val) {
                  setState(() {
                    checkboxValue = !checkboxValue;
                  });
                },
                subtitle: !checkboxValue
                    ? Text(
                  'Required.',
                  style: TextStyle(color: Colors.red),
                )
                    : null,
                title: GestureDetector(
                  onTap: (){
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (BuildContext context){
                          return Page();
                        },
                      ),
                    );
                  },
                  child: Text(
                    'I agree to the Terms and Conditions.',
                    style: TextStyle(fontSize: 14.0),
                  ),
                ),
                controlAffinity: ListTileControlAffinity.leading,
                activeColor: Colors.green,
              )

Wrap your text with Inkwell or GestureDetector .使用InkwellGestureDetector包裹您的文本。

Sample code here:示例代码在这里:

GestureDetector(
            onTap: () { },
            child: Text(
              "Sample Text",
              style: TextStyle(
                  fontWeight: FontWeight.w800, color: Colors.blue
              ),
            ),
          )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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