textfield基本使用
TextField(
maxLines: 100,
textAlign: TextAlign.right,
keyboardType: TextInputType.text,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
border: InputBorder.none,
hintText: "請(qǐng)輸入",
hintStyle: TextStyle(fontSize: 14,color: Colors.grey),
),
),
簡(jiǎn)單富文本可以直接設(shè)置
var _editingController = TextEditingController()
_editingController.value = TextEditingValue(text: str, composing: TextRange(start: 1, end: 13));

image.png
修改文本顏色需要重寫(xiě) buildTextSpan 方法, 更改 TextStyle
class OverTextEditingController extends TextEditingController{
@override
TextSpan buildTextSpan({BuildContext context, TextStyle style , bool withComposing}) {
if (!value.isComposingRangeValid || !withComposing) {
return TextSpan(style: style, text: text);
}
final TextStyle composingStyle = style.merge(
const TextStyle(Colors: Colors.blue),
);
return TextSpan(
style: style,
children: <TextSpan>[
TextSpan(text: value.composing.textBefore(value.text)),
TextSpan(
style: composingStyle,
text: value.composing.textInside(value.text),
),
TextSpan(text: value.composing.textAfter(value.text)),
],
);
}
}
var _editingController = TextEditingController()
要改成
var _editingController = OverTextEditingController()
#如若報(bào)屬性不符錯(cuò)誤 需重新運(yùn)行項(xiàng)目

image.png
多重富文本也在 TextSpan buildTextSpan({BuildContext context, TextStyle style , bool withComposing}) 方法中修改
針對(duì)富文本需求進(jìn)行 TextSpan
end