簡體   English   中英

使用 Flutter 在可點擊的圖像上顯示文本

[英]Display text over a clickable image using Flutter

我正在嘗試在可點擊的圖像上顯示一些文本。 我使用 InkWell 小部件使圖像可點擊,並使用 Stack 小部件覆蓋 Text 小部件:

new Expanded(
  child: new Stack(
    children: <Widget>[
      new InkWell(
        onTap: (){ _doSomething(); },
        child: Image.asset("images/my-image.jpg"),
      ),
      new Text("Some text"),
    ],
  ),
)

這樣我只能點擊沒有填充文本的圖像部分,這不好。 即使點擊覆蓋文本,我也希望我的功能運行。

我嘗試使用 FlatButton 小部件而不是 Text 並且以某種方式工作,但我確定這不是正確的方法。 你有什么建議嗎?

new Expanded(
  child: new Stack(
    children: <Widget>[
      new InkWell(
        onTap: (){ _doSomething(); },
        child: Image.asset("images/my-image.jpg"),
      ),
      new FlatButton(
        onPressed: (){_doSomething;},
        child: Text("Some text"),
      )
    ],
  ),
),

將堆棧放入墨水瓶內。

Expanded(
      child: InkWell(
        onTap: () => _doSomething(),
        child: Stack(
          children: <Widget>[
            Image.asset("images/my-image.jpg"),
            Text("Some text"),
          ],
        ),
      ),
    )

如果您將InkWell移到堆棧的更高位置會怎樣?

Expanded(
  child: InkWell(
    onTap: (){ _doSomething(); },
    child: Stack(
      children: <Widget>[
        Image.asset("images/my-image.jpg"),
        Text("Some text"),
      ],
    ),
  ),
),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM