LoginSignup
24
16

More than 3 years have passed since last update.

Flutter TextFieldの装飾

Last updated at Posted at 2020-09-16

Flutter で 「入力欄にボーダー設定したいけど、どうするんだろう」 と調べた時に、あまりに基本的な事すぎて?しばらく見つけられなかったので備忘録を兼ねたメモです。

スクリーンショット

ボーダーとかアイコンを設定するとスクリーンショットにあるような入力欄が作れます。

ソースコード

TextField に InputDecoration で設定しています。

class MyWidget extends StatelessWidget {
  const MyWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Center(
          child: Container(
            padding: const EdgeInsets.all(30),
            child: Form(
              child: Column(
                children: [
                  const Text('テキスト入力の装飾'),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      labelText: 'デフォルト',
                    ),
                  ),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'ボーダーあり',
                    ),
                  ),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'アイコンあり',
                      icon: Icon(Icons.send),
                    ),
                  ),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'エラーあり',
                      errorText: 'ここにエラーメッセージ',
                    ),
                  ),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'Prefix, Suffix',
                      prefix: Text('Prefix'),
                      suffix: Text('Suffix'),
                    ),
                  ),
                  const SizedBox(height: 20),
                  TextFormField(
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'Prefix, Suffix アイコン',
                      prefixIcon: Icon(Icons.face),
                      suffixIcon: Icon(Icons.face_outlined),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
24
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
16