이 튜토리얼에서는 TextField 또는 TextFormField를 클릭할 때 키보드 팝업을 비활성화하는 방법을 알아봅니다. 사용자 정의 키보드, 직접 디자인한 키워드 등을 사용할 때와 같은 여러 조건에서 키보드 팝업을 비활성화해야 할 수도 있습니다. 아래 예를 보고 텍스트 필드에서 키보드 팝업을 비활성화하는 방법을 알아보세요.
TextField(
keyboardType: TextInputType.none,
)
텍스트 필드에서 키보드 팝업을 비활성화하는 데 복잡하거나 큰 작업이 필요하지 않습니다. 위 코드를 사용하여 텍스트 필드의 키보드 유형을 없음으로 변경하면 됩니다.
또는 다음 코드를 사용하여 키보드 팝업 TextField를 비활성화할 수도 있습니다.
TextField(
showCursor: true,
readOnly: true
),
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Home(),
);
}
}
class Home extends StatefulWidget{
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Disable Keyboard Popup on TextField"),
backgroundColor: Colors.redAccent
),
body: Container(
child: Column(
children: [
TextField(
keyboardType: TextInputType.none,
),
TextFormField(
showCursor: true,
readOnly: true,
)
],
)
)
);
}
}
이런 방식으로 Flutter에서 클릭하면 TextField 또는 TextFormField에서 키보드 팝업을 비활성화할 수 있습니다.