0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

onFieldSubmitted時にテキストをクリアする方法

Last updated at Posted at 2024-05-02

概要

Flutter初心者によるFlutter初心者のための記事になります。
TextFormField使ってonFieldSubmittedを発火させた後に入力した文字消えないの気持ち悪いなと思って調べてみました。

実装

TextFormFieldのテキストをクリアするには、TextEditingControllerを使います。

実装方法は下記になります。

final _editController = TextEditingController();

TextFormField(
    controller: _editController,
    onFieldSubmitted: (text) {
    // 〜〜〜〜〜〜〜
     _editController.clear(); // TextFormFieldのテキストをクリア
    },
),

実際の動きはこんな感じになります。
qiita.gif

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?