Flutter TextFormFieldの文字数を制限する方法

環境
Windows11 pro 64bit
Flutter 3.3.7

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
TextFormField(
maxLength: /*最大文字数*/,
),
TextFormField( maxLength: /*最大文字数*/, ),
TextFormField(
  maxLength: /*最大文字数*/,
),

TextFormFieldの引数「maxLength」に最大文字数を指定します。
引数「maxLength」を使えば、TextFormFieldの文字数に制限をかけることができます。

操作例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
maxLength: 20,
),
),
),
);
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( maxLength: 20, ), ), ), ); }
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: TextFormField(
          maxLength: 20,
        ),
      ),
    ),
  );
}

 

Flutter

Posted by arkgame