どうも、ちょげ(@chogetarou)です。
OutlinedButtonの横幅を設定する方法を紹介します。
方法

OutlinedButtonの横幅を設定するには、引数「style」を使います。
まず、OutlinedButtonの引数「style」にOutlinedButton.styleFromを指定します。
そして、styleFromの引数「fixedSize」に横幅を指定します。
横幅の指定は、Sizeクラスでします。
OutlinedButton(
style: OutlinedButton.styleFrom(
fixedSize: Size.fromWidth(横幅), //Sizeクラスで横幅を指定
),
onPressed: () {},
child: Text('Button'),
),
OutlinedButton.styleFromの引数「fixedSize」に指定した横幅が、OutlinedButtonの横幅に設定されます。
使用例

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
fixedSize: Size.fromWidth(200.0),
),
onPressed: () {},
child: Text('Button'),
),
),
),
);
}
コメント