[Flutter]OutlinedButtonのスプラッシュカラーを変えるには?

Flutter

どうも、ちょげ(@chogetarou)です。

OutlinedButtonのスプラッシュカラーを変える方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

OutlinedButtonのスプラッシュカラーを変えるには、引数「style」を使います。

まず、OutlinedButtonの引数「style」にOutlinedButton.styleFromを指定します。

そして、styleFromの引数「primary」にスプラッシュカラーを指定します。

OutlinedButton(
  style: OutlinedButton.styleFrom(
    primary: splashColor, //スプラッシュカラー
  ),
  onPressed: () {},
  child: Text('Button'),
),

OutlinedButton.styleFromの引数「primary」に指定した色が、OutlinedButtonのスプラッシュカラーに設定されます。

styleFromの引数「primary」は、テキストカラーの色も設定します。

使用例

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: OutlinedButton(
            style: OutlinedButton.styleFrom(
              primary: Colors.red,
            ),
            onPressed: () {},
            child: Text('Button'),
          ),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました