どうも、ちょげ(@chogetarou)です。
OutlinedButtonのテキストカラーを変える方法を紹介します。
方法

OutlinedButtonのテキストの色を変える方法は、2つあります。
style
1つは、OutlinedButtonの引数「style」を使う方法です。
まず、OutlinedButtonの引数「style」にOutlinedButton.styleFrom()を指定します。
そして、styleFromの引数「primary」にテキストカラーを指定します。
OutlinedButton(
style: OutlinedButton.styleFrom(
primary: textColor, //テキストの色を指定
),
onPressed: () {},
child: Text('Button'),
),
使用例

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
primary: Colors.red,
),
onPressed: () {},
child: Text('Button'),
),
),
),
);
}
Textのstyle
もう1つは、Textの引数「style」を使う方法です。
まず、Textの引数「style」にTextStyleを指定します。
そして、TextStyleの引数「color」にテキストカラーを指定します。
OutlinedButton(
onPressed: () {},
child: Text(
'Button',
style: TextStyle(
color: textColor, //テキストカラーを指定
),
),
),
使用例

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: OutlinedButton(
onPressed: () {},
child: Text(
'Button',
style: TextStyle(
color: Colors.yellow,
),
),
),
),
),
);
}
まとめ
OutlinedButtonをテキストの色を変える方法は、次の2つです。
- OutlinedButtonの引数「style」を使う方法
- Textの引数「style」を使う方法
コメント