본문 바로가기

TextEditingController3

Flutter의 TextField에서 값의 끝에 커서 위치를 설정하는 방법은 무엇인가요?, how to set cursor position at the end of the value in flutter in textfield? 질문 저는 텍스트 필드의 값 끝에 ,00을 추가하고 싶습니다. iOS 기기에서는 잘 작동하지만 Android에서는 커서가 텍스트 필드의 값 시작 지점으로 이동합니다. 결과적으로 ,00을 추가할 수 없습니다. 답변 저는 TextEditingController을 설정하는 데 동일한 문제를 겪고 있었는데, 이게 제게 작동했습니다. controller.text = someString; controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length)); TextSelection.fromPosition()은 다음을 수행합니다 (문서에서): 주어진 텍스트 위치에서 축소된 선택을 생성합니다. 축소된 선택은 시작과 .. 2023. 5. 28.
Flutter에서 텍스트 필드 내부의 값을 어떻게 변경하나요?, How do you change the value inside of a textfield flutter? 질문 사용자가 버튼을 클릭하면 정보가 채워지는 TextEditingController가 있습니다. Textfield 또는 TextFormField 내부의 텍스트를 변경하는 방법을 찾을 수 없습니다. 해결책이 있을까요? 답변 text 속성을 간단히 변경하십시오. TextField( controller: txt, ), RaisedButton(onPressed: () { txt.text = "My Stringt"; }), txt는 단지 TextEditingController일 뿐입니다. var txt = TextEditingController(); 2023. 5. 26.
Flutter TextField 위젯에 Clear 버튼을 추가하는 방법, How to add clear button to TextField Widget 질문 TextField에 클리어 버튼을 추가하는 올바른 방법이 있나요? Material design 가이드라인에서 보는 것처럼: 찾아본 결과, InputDecoration의 suffixIcon에 클리어 IconButton을 설정하는 것이 맞는 방법인가요? 답변 출력: 변수를 만드세요 var _controller = TextEditingController(); 그리고 TextField를 추가하세요: TextField( controller: _controller, decoration: InputDecoration( hintText: '메시지를 입력하세요', suffixIcon: IconButton( onPressed: _controller.clear, icon: Icon(Icons.clear), ), ), ) 2023. 5. 18.