我目前正在尝试在Flutter中创建自定义样式的按钮。我希望创建一个与此https://raw.githubusercontent.com/hoang8f/android-flat-button/master/screenshot/screenshot.gif
相似的按钮我可以使用RaisedButton创建类似的东西吗,还是需要使用CustomPainter通过自定义绘图来创建它?但是,在使用height参数时,RaisedButton似乎没有创建所需的效果。
答案 0 :(得分:1)
您可以创建一个StatefulWidget
并使用GestureDetector
class MyCustomButton extends StatefulWidget {
@override
_MyCustomButtonState createState() => _MyCustomButtonState();
}
class _MyCustomButtonState extends State<MyCustomButton> {
bool _isPressed = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: (TapDownDetails details) {
setState(() {
_isPressed = true;
});
},
onTapUp: (TapUpDetails details) {
setState(() {
_isPressed = false;
});
},
child: Container(
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.blue,
border: _isPressed
? Border(bottom: BorderSide(color: Colors.grey, width: 10.0))
: null,
),
child: Text("title button")),
);
}
}