How can I create Textfeild with multi input boxes, same like in picture with controller
Asked
Active
Viewed 123 times
0
-
2Can you include what you've tried so far? – Md. Yeasin Sheikh Jul 27 '22 at 16:14
-
I think you are looking for something like [pin_code_fields](https://pub.dev/packages/pin_code_fields) – returnVoid Jul 27 '22 at 16:26
-
i need more than length : 6 ,, i need like 15 – husam Jul 27 '22 at 19:22
-
@husam you can set the length. "Can be set to any length." <- from the link I provided. – returnVoid Jul 27 '22 at 20:08
1 Answers
0
You can create this UI with TextFormFiled with OutlineInputBorder
.You can follow this for this question
Also you can use pin_code_fields package for this.
child: PinCodeTextField(
pinTheme: PinTheme(shape: PinCodeFieldShape.box),
appContext: context,
length: 15,
blinkWhenObscuring: true,
animationType: AnimationType.fade,
keyboardType: TextInputType.number,
onCompleted: (v) {
debugPrint("Completed");
},
onChanged: (value) {
debugPrint(value);
},
),
Using this
int numberOfItem = 15;
Widget _textFieldOTP(BuildContext context, {required bool first, last}) {
return Container(
height: 54,
width: 53,
child: TextFormField(
autofocus: true,
onChanged: (value) {
if (value.length == 1 && last == false) {
FocusScope.of(context).nextFocus();
}
if (value.length == 0 && first == false) {
FocusScope.of(context).previousFocus();
}
},
showCursor: false,
readOnly: false,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 1,
decoration: InputDecoration(
counterStyle: TextStyle(height: double.minPositive),
counterText: "",
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Color(0x1A484848)),
borderRadius: BorderRadius.circular(6),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Color(0xFFFF2957)),
borderRadius: BorderRadius.circular(6),
),
),
),
);
}
And using it like
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(numberOfItem, (index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _textFieldOTP(context,
first: index == 0, last: index == numberOfItem - 1),
);
}),
),
),

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56
-
-
You can create a state string variable and use `onChanged` value to get the text. Also you can use TextEditingController on `PinCodeTextField` – Md. Yeasin Sheikh Jul 27 '22 at 19:10
-
-
-
-