基本用法

  1. Container(
  2. width: _width,
  3. height: 100,
  4. alignment: Alignment.center,
  5. margin: EdgeInsets.fromLTRB(15, (_height / 2 ) - 100, 15, 0),
  6. decoration: BoxDecoration(
  7. color: Colors.green[300],
  8. borderRadius: BorderRadius.circular(15)
  9. ),
  10. child: RaisedButton(
  11. onPressed : (){
  12. print("onPressed"); // 按下触发。//可以通过这个设置禁用或启用控件
  13. },
  14. onLongPress: (){
  15. print("onLongPress"); // 长按触发。
  16. },
  17. onHighlightChanged: (e){ //水波纹高亮变化回调,按下返回true,抬起返回false
  18. print("onHighlightChanged, $e");
  19. },
  20. textTheme: ButtonTextTheme.primary,
  21. textColor: Colors.white, // 按钮不在禁用状态的颜色。
  22. disabledTextColor : Colors.yellow[200], // 按钮禁用的时候字体文字的颜色。
  23. color: Colors.red[300], // 按钮的背景颜色
  24. disabledColor: Color(0xffff9800), // 禁用状态的背景色。
  25. focusColor : Colors.black,
  26. hoverColor : Colors.white,
  27. // highlightColor : Colors.white, // 长按的背景色。
  28. splashColor : Colors.yellow[300], // 水波的颜色。
  29. colorBrightness : Brightness.dark,
  30. elevation : 8.0, // 按钮 阴影 高度
  31. focusElevation : 2.0, // 按钮 的背景阴影
  32. hoverElevation : 2.0,
  33. highlightElevation : 2.0, // 按钮长按 时阴影高度。
  34. disabledElevation : 6.0, // 禁用状态的阴影高度。
  35. padding : EdgeInsets.only( left : 30.0, top : 30.0, right : 20.0, bottom : 20.0),
  36. visualDensity : VisualDensity(horizontal: 3.4, vertical: 1.0), // 视觉密度
  37. shape : RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0)), // 外观。
  38. // materialTapTargetSize : MaterialTapTargetSize.padded,
  39. child: Text("Buttom"),
  40. )
  41. )

WX20200914-110620.pngWX20200914-110629.png
image.png

关于 shape 设置外观【形状】

BeveledRectangleBorder 长方形设置边框

  1. Row(
  2. children: <Widget>[
  3. // 斜角巨型
  4. _Buttom(
  5. BeveledRectangleBorder(
  6. side: BorderSide(width: 1, color: Colors.red),
  7. borderRadius: BorderRadius.circular(10)
  8. )
  9. ),
  10. _Buttom(
  11. BeveledRectangleBorder(
  12. side: BorderSide(width: 1, color: Colors.red),
  13. borderRadius: BorderRadius.circular(60)
  14. )
  15. ),
  16. _Buttom(
  17. BeveledRectangleBorder(
  18. side: BorderSide(width: 1, color: Colors.red),
  19. borderRadius: BorderRadius.circular(0)
  20. )
  21. )
  22. ],
  23. ),

Border 设置边框

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. Border(
  5. top : BorderSide(color : Colors.black, width: 3)
  6. )
  7. ),
  8. _Buttom(
  9. Border(
  10. bottom : BorderSide(color : Colors.black, width: 3)
  11. )
  12. ),
  13. _Buttom(
  14. Border(
  15. right : BorderSide(color : Colors.black, width: 3)
  16. )
  17. ),
  18. ],
  19. )

CircleBorder 圆形设置边框

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. CircleBorder(side: BorderSide(color: Colors.black)),
  5. )
  6. ],
  7. ),

ContinuousRectangleBorder 椭圆边框

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. ContinuousRectangleBorder(
  5. side: BorderSide(color: Colors.red),
  6. borderRadius: BorderRadius.circular(30)
  7. ),
  8. )
  9. ],
  10. ),

RoundedRectangleBorder 圆角边框

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. RoundedRectangleBorder(
  5. side: BorderSide(color: Colors.red),
  6. borderRadius: BorderRadius.circular(30)
  7. ),
  8. )
  9. ],
  10. ),

StadiumBorder 运动场边框 和 圆角边框差不多

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. StadiumBorder(
  5. side: BorderSide(color: Colors.red),
  6. ),
  7. )
  8. ],
  9. ),

OutLineInputBorder 圆角边框。

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. OutlineInputBorder(
  5. borderSide: BorderSide(color: Colors.red),
  6. borderRadius: BorderRadius.circular(30),
  7. ),
  8. )
  9. ],
  10. )

UnderlineInputBorder 底下边框 上边圆角

  1. Row(
  2. children: <Widget>[
  3. _Buttom(
  4. UnderlineInputBorder(
  5. borderSide: BorderSide(color: Colors.red, width: 4),
  6. ),
  7. )
  8. ],
  9. )

基础代码

  1. Widget _Buttom(_shape) {
  2. return RaisedButton(
  3. onPressed: () {
  4. print("onPressed"); // 按下触发。//可以通过这个设置禁用或启用控件
  5. },
  6. onLongPress: () {
  7. print("onLongPress"); // 长按触发。
  8. },
  9. onHighlightChanged: (e) {
  10. //水波纹高亮变化回调,按下返回true,抬起返回false
  11. print("onHighlightChanged, $e");
  12. },
  13. textColor: Colors.white, // 按钮不在禁用状态的颜色。
  14. disabledTextColor: Colors.yellow[200], // 按钮禁用的时候字体文字的颜色。
  15. color: Color(0xffff9800), // 按钮的背景颜色
  16. disabledColor: Color(0xffff9800), // 禁用状态的背景色。
  17. focusColor: Colors.black,
  18. hoverColor: Colors.white,
  19. // highlightColor : Colors.white, // 长按的背景色。
  20. splashColor: Colors.yellow[300], // 水波的颜色。
  21. colorBrightness: Brightness.dark,
  22. elevation: 8.0, // 按钮 阴影 高度
  23. focusElevation: 2.0, // 按钮 的背景阴影
  24. hoverElevation: 2.0,
  25. highlightElevation: 2.0, // 按钮长按 时阴影高度。
  26. disabledElevation: 6.0, // 禁用状态的阴影高度。
  27. // padding:
  28. // EdgeInsets.only(left: 30.0, top: 30.0, right: 20.0, bottom: 20.0),
  29. visualDensity: VisualDensity(horizontal: 3.4, vertical: 1.0), // 视觉密度
  30. shape:_shape, // 外观。
  31. // materialTapTargetSize : MaterialTapTargetSize.padded,
  32. child: Text("Buttom"),
  33. );
  34. }
  35. }

WX20200914-155758.png