값을 입력하는 동안 모든 입력 텍스트에 맞게 텍스트 필드의 너비를 동적으로 변경하고 싶습니다. 이것이 내가 시도한 것입니다.
var valueIncreaser = 30;
var textfieldSpanValue = 50.0;
Container(
width: textfieldSpanValue,
child: TextFormField(
onChanged: (text) {
setState(() {
textfieldSpanValue = 20;
textfieldSpanValue = valueIncreaser + textfieldSpanValue * textfieldSpanValue;
});
},
controller: myController,
maxLength: 10,
maxLengthEnforced: true,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
),
)
코드에 간단한 논리적 실수가있는 것 같습니다. 필요한 것은 너비 증분 논리를 다음과 같이 설정하는 것입니다.
textfieldSpanValue = valueIncreaser + textfieldSpanValue * text.length;
var valueIncreaser = 30;
var textfieldSpanValue = 50.0;
Container(
width: textfieldSpanValue,
child: TextFormField(
onChanged: (text) {
setState(() {
textfieldSpanValue = 20;
textfieldSpanValue =
valueIncreaser + textfieldSpanValue * text.length;
});
},
controller: myController,
maxLength: 10,
maxLengthEnforced: true,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
),
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다