我有一個按鈕,有一個圖像作爲一個孩子。我需要它,以便在按下按鈕的同時,圖像變爲另一個圖像,並且當用戶停止按下按鈕時,圖像會返回到其原始圖像。如何製作一個帶有顫動圖像的按鈕,當somone按下時突出顯示圖像?
基本上我希望它像一個凸起的按鈕,但與自定義圖像的凸起和按下狀態。
下面是相關代碼:
class LoginButton extends StatefulWidget {
@override
_LoginButtonState createState() => new _LoginButtonState();
}
class _LoginButtonState extends State<LoginButton> {
void _onClicked() {
setState(() {
//I don't know what I should put here to cause the image to redraw
//only on button press
});
}
@override
Widget build(BuildContext context) {
var assetImage = new AssetImage("assets/loginscreen/btn.png");
var image = new Image(image: assetImage, height: 50.0, width: 330.0);
return new Container(
height: image.height,
width: image.width,
child: new FlatButton(
onPressed: _onClicked,
child: new ConstrainedBox(
constraints: new BoxConstraints.expand(),
child: image,
),
),
);
}
}
我有更多的相關代碼的答案更新,你想達到的目標。 – aziza