I am new to flutter world
I tried to direct the `TextFormField in this way, and this error in the title appeared
I want to use Directionality textDirection: TextDirection.rtl
,
but this what happened
Widget _buildName() {
Directionality(
textDirection: TextDirection.rtl,
child: TextFormField(
textAlign: TextAlign.right,
decoration: InputDecoration(labelText: 'الاسم', hintText: 'أدخل اسمك'),
maxLength: 10,
validator: (String? value) {
if (value!.isEmpty) {
return 'يجب أن لا يكون الحقل فارغًا';
}
return null;
},
onSaved: (String? value) {
_name = value;
},
));
}
CodePudding user response:
you are getting the error because you are not returning anything. add return
keyword before Directionality() and it should work:
Widget _buildName() {
return Directionality(
textDirection: TextDirection.rtl,
child: TextFormField(
textAlign: TextAlign.right,
decoration: InputDecoration(labelText: 'الاسم', hintText: 'أدخل اسمك'),
maxLength: 10,
validator: (String? value) {
if (value!.isEmpty) {
return 'يجب أن لا يكون الحقل فارغًا';
}
return null;
},
onSaved: (String? value) {
_name = value;
},
));
}
CodePudding user response:
Try this
Widget _buildName() {
Directionality(
textDirection: TextDirection.rtl,
child: TextFormField(
textAlign: TextAlign.right,
decoration: InputDecoration(labelText: 'الاسم', hintText: 'أدخل اسمك'),
maxLength: 10,
validator: (String? value) {
if (value!.isEmpty) {
return 'يجب أن لا يكون الحقل فارغًا';
}
return '';///here
},
onSaved: (String? value) {
_name = value;
},
));
}