본문 바로가기
Flutter/Flutter FAQ

Flutter에서 숫자 입력 필드를 만드는 방법은 무엇인가요?, How to create number input field in Flutter?

by 베타코드 2023. 5. 8.
반응형

질문

I'm unable to find a way to create an input field in Flutter that would open up a numeric keyboard and should take numeric input only. Is this possible with Flutter material widgets? Some GitHub discussions seem to indicate this is a supported feature but I'm unable to find any documentation about it.

답변

당신은 keyboardType을 사용하여 TextField에 숫자를 지정할 수 있습니다:

keyboardType: TextInputType.number 

내 main.dart 파일을 확인하세요

import 'package:flutter/material.dart'; import 'package:flutter/services.dart';  void main() => runApp(new MyApp());  class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     // TODO: implement build     return new MaterialApp(       home: new HomePage(),       theme: new ThemeData(primarySwatch: Colors.blue),     );   } }  class HomePage extends StatefulWidget {   @override   State<StatefulWidget> createState() {     return new HomePageState();   } }  class HomePageState extends State<HomePage> {   @override   Widget build(BuildContext context) {     return new Scaffold(       backgroundColor: Colors.white,       body: new Container(           padding: const EdgeInsets.all(40.0),           child: new Column(         mainAxisAlignment: MainAxisAlignment.center,         children: <Widget>[           new TextField(             decoration: new InputDecoration(labelText: "Enter your number"),             keyboardType: TextInputType.number,             inputFormatters: <TextInputFormatter>[     FilteringTextInputFormatter.digitsOnly ], // Only numbers can be entered           ),         ],       )),     );   } } 

enter image description here

반응형

댓글