[Flutter]CupertinoButtonの使い方

Flutter

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

CupertinoButtonの使い方を解説します。

スポンサーリンク

使い方

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

CupertinoButton

CupertinoButtonを使うには、次の2つの引数を使う必要があります。

  • child : ボタンに表示するウェジェット
  • onPressed : タップした時に呼び出される関数

「child」には、テキストやアイコンなどのウェジェットを指定します。

そして、「onPressed」には、タップした時に行いたい処理を関数で指定します。

            CupertinoButton(
              child: Text('Button'),
              onPressed: () {},
            )

CupertinoButton.filled

CupertinoButtonは、filledコンストラクタを使うことで角丸のボタンを作ることが出来ます。

filledコンストラクタの引数は、通常のボタンと同じように指定します。

            CupertinoButton.filled(
              child: Text('Button'),
              onPressed: () {},
            )

ボタンを無効にする

CupertinoButtonをタップできないようにするには、「onPressed」に「null」を指定します。

            CupertinoButton.filled(
              child: Text('Button'),
              onPressed: null,
            )

また、有効と無効を切り替えたい場合は、三項演算子を使います。

            CupertinoButton.filled(
              child: Text('Button'),
              onPressed: _isDisabled ? null : (){},
            )

まとめ

CupertinoButtonは、引数「child」と引数「onPressed」を指定して使います。

また、「filled」コンストラクタを使うことで、角丸の色付きボタンを表示することが出来ます。

コメント

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