我建议创建一个“扩展”Flutter MaterialButton 或 RawMaterialButton 的自定义按钮。如果您希望按钮可重用,请记住将 buttonText 添加为参数。还记得在 Text 小部件样式中添加 TextStyle(fontFamily: 'Raleway')。
另一种选择是以与下面的按钮示例相同的方式“扩展” Flutter Text 小部件,并将您的 CustomTextWidget 作为子级添加到 Flutter MaterialButton 小部件。我更喜欢两者结合使用。 CustomButton 和 CustomText 小部件。
import 'package:flutter/material.dart';
class CustomButton extends StatelessWidget {
CustomButton({@required this.onPressed});
final GestureTapCallback onPressed;
@override
Widget build(BuildContext context) {
return RawMaterialButton(
fillColor: Colors.green,
splashColor: Colors.greenAccent,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: const <Widget>[
Icon(
Icons.face,
color: Colors.amber,
),
SizedBox(
width: 10.0,
),
Text(
"Tap Me",
maxLines: 1,
style: TextStyle(color: Colors.white),
),
],
),
),
onPressed: onPressed,
shape: const StadiumBorder(),
);
}
}
这里是实现:
CustomButton(
onPressed: () {
print("Tapped Me");
},
)