LoginSignup
3
0

More than 1 year has passed since last update.

Dartで空白を除去する方法

Last updated at Posted at 2020-06-14

phpで例えるならtrimのように空白を除去してくれる関数はないのかとdocumentを見たら、あった。
api.dart - trim

動作確認は
dartpadでしてる

前後の空白を除去

void main() {
  const String email = ' example@hoge ';
  print(email.trim());
}

//結果
//「example@hoge」

末尾の空白を除去

void main() {
  const String email = ' example@hoge ';
  print(email.trimRight());
}

//結果
//「 example@hoge」

先頭の空白を除去

void main() {
  const String email = ' example@hoge ';
  print(email.trimLeft());
}

//結果
//「example@hoge 」

んで今回はログイン時にメールアドレスを入力するが、その時に入った空白を除去するといったようにしたかったのでこう書いた。


children: <Widget>[
TextFormField(
  decoration: const InputDecoration(labelText: 'メールアドレス'),
  onChanged: (String value) {
    setState(() {
      email = value.trim();
     });
    },
 ),

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