gesturedetector.java_我的flutter代码中的GestureDetector不起作用
我正在玩flip_card package(這個(gè)軟件包會(huì)創(chuàng)建一張卡片,當(dāng)你點(diǎn)擊它時(shí),它會(huì)翻轉(zhuǎn)卡片并顯示卡片的正面或背面) . 我想要做的是,每次點(diǎn)擊卡片時(shí)顯示不同的圖像,并且卡片翻轉(zhuǎn)到正面 .
為此,我將flip_card example修改為有狀態(tài)小部件,并使用GestureDetector檢測(cè)水龍頭:
_renderContent(context) {
return Card(
elevation: 0.0,
margin: EdgeInsets.only(left: 32.0, right: 32.0, top: 10.0, bottom: 0.0),
color: Color(0x00000000),
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _tapHandler,
child: Container(
decoration: BoxDecoration(
color: Color(0xFF006666),
borderRadius: BorderRadius.all(Radius.circular(8.0)),
boxShadow: [BoxShadow(blurRadius: 15.0, spreadRadius: 0.8)],
image: DecorationImage(
image: AssetImage(_cards[_cardInd]),
fit: BoxFit.cover,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Back', style: Theme.of(context).textTheme.headline),
Text('Click here to flip front',
style: Theme.of(context).textTheme.body1),
],
),
),
),
back: Container(
decoration: BoxDecoration(
color: Color(0xFF006666),
borderRadius: BorderRadius.all(Radius.circular(8.0)),
boxShadow: [BoxShadow(blurRadius: 15.0, spreadRadius: 0.8)],
image: DecorationImage(
image: AssetImage(_cards[0]),
fit: BoxFit.cover,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Back', style: Theme.of(context).textTheme.headline),
Text('Click here to flip front',
style: Theme.of(context).textTheme.body1),
],
),
),
),
);
}
而tapHandler函數(shù)是:
void _tapHandler() {
setState(() {
_cardInd = x.nextInt(_cards.length);
});
print("_cardInd $_cardInd");
}
_cardInd 是圖像資源列表 _cards 的索引 . 但是,GestureDetector不起作用 . 圖像不會(huì)改變,也不會(huì)在屏幕上打印 print("_cardInd $_cardInd"); .
有人可以幫助我,以便當(dāng)我點(diǎn)擊卡片時(shí)圖像會(huì)發(fā)生變化嗎?
總結(jié)
以上是生活随笔為你收集整理的gesturedetector.java_我的flutter代码中的GestureDetector不起作用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Google File System设计
- 下一篇: 深度装机大师一键重装_“云骑士一键重装系