18
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FlutterでPassword用のTextFieldを実装する

Posted at

スマホアプリのパスワード入力欄でありがちなパスワードの表示/非表示を切り替えられるTextFieldをFlutterで実装する方法です。

TextField(
    obscureText: !_showPassword,
    controller: _passwordTextController,
    decoration: InputDecoration(
        labelText: "Password",
        suffixIcon: IconButton(
            icon: Icon(_showPassword
                ? FontAwesomeIcons.solidEye
                : FontAwesomeIcons.solidEyeSlash),
            onPressed: () {
            this.setState((){
                _showPassword = !_showPassword;
            });
            },
        )),
    )

obscureTextプロパティ で パスワードの表示/非表示を指定することができます。
decoration プロパティの suffixIcon でTextFiledの右側にアイコンを設置できるので、そのボタンをタップした時に ステートを変更することでパスワードの表示/非表示を切り替えられます。

18
10
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
18
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?