簡體   English   中英

如何在 Flutter 上創建從 CheckboxlistTile 到另一個頁面的“鏈接”

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

我正在制定條款和條件協議,我希望突出顯示並可點擊這句話,點擊后應該將用戶帶到應用程序中的另一個頁面,他們可以在其中閱讀協議。 我在創建既可點擊又突出顯示的內容時遇到問題。

這是我的代碼:

 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,
    ),
    ```

GestureDetector()包裝您的 Text 小部件。 見下面的代碼

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,
              )

使用InkwellGestureDetector包裹您的文本。

示例代碼在這里:

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