Issue
I have a AppTextField in flutter app as follow:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
class AppTextField extends StatefulWidget {
final int maxLines;
final String? title;
final TextInputType? keyboardType;
final bool autoFocus;
final TextInputAction inputAction;
final bool isSuffixIcon;
AppTextField(
{this.title,
this.maxLines: 1,
this.keyboardType,
this.autoFocus: false,
this.inputAction: TextInputAction.next,
this.isSuffixIcon: false});
@override
State<StatefulWidget> createState() => AppTextFieldSate();
}
class AppTextFieldSate extends State<AppTextField> {
String? text = '';
bool isRTL(String text) {
return intl.Bidi.detectRtlDirectionality(text);
}
@override
Widget build(BuildContext context) => Container(
child: TextField(
textDirection: isRTL(text!) ? TextDirection.rtl : TextDirection.ltr,
textInputAction: widget.inputAction,
keyboardType: widget.keyboardType,
autofocus: widget.autoFocus,
style: Theme.of(context).textTheme.bodyText1,
maxLines: widget.maxLines,
decoration: InputDecoration(
labelText: widget.title,
suffixIcon: widget.isSuffixIcon
? Icon(Icons.check_circle, color: Theme.of(context).hintColor)
: Container(),
),
onChanged: (value) {
setState(() {
text = value;
});
}));
}
When I use maxLines in AppTextField, there is a problem!
AppTextField(maxLines: 5, keyboardType: TextInputType.multiline)
Only one character is entered in a line as follow picture:
My question is:
Why occur this problem and I how to resolve it?
Solution
I resolved it :) I must use null instead of Container in suffixIcon widget. Container widget make to problem.
suffixIcon: widget.isSuffixIcon
? Icon(Icons.check_circle, color: Theme.of(context).hintColor)
: null,
Answered By - Ehsan Kalali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.