当前位置:网站首页>Flutter apple native Pinyin keyboard input exception on textfield | Pinyin input process callback problem
Flutter apple native Pinyin keyboard input exception on textfield | Pinyin input process callback problem
2022-07-25 02:20:00 【Crazy fox 12138】
Flutter Normal text callback passed onChange Handle , It can also be done through monitor TextEditingController Handle
monitor TextEditingController

adopt value.composing To judge , The first judgment is entered directly , Then return directly to a normal style . The second judgment is that there are unfinished characters ,**value.composing.textInside(value.text)** What you get is the input of incomplete characters , The default is to add an underline style , Similar to a gray black background in apple native input , In this way, you can directly achieve the same effect as the native Chinese keyboard input .
therefore Direct inheritance TextEditingController Rewrite this rich text method to handle
class ChangeTextEditingController extends TextEditingController {
var completeText = '';
// There are other methods that can be directly added here to inherit Use
ChangeTextEditingController.fromValue(TextEditingValue value)
: super.fromValue(value);
@override
TextSpan buildTextSpan(
{BuildContext context, TextStyle style, bool withComposing}) {
/// Pinyin input completed
if (!value.composing.isValid || !withComposing) {
if (completeText != value.text) {
completeText = value.text;
WidgetsBinding.instance.addPostFrameCallback((_) {
notifyListeners();
});
}
return TextSpan(style: style, text: text);
}
/// Returns the input style , Customizable styles
final TextStyle composingStyle = style.merge(
const TextStyle(decoration: TextDecoration.underline),
);
return TextSpan(style: style, children: <TextSpan>[
TextSpan(text: value.composing.textBefore(value.text)),
TextSpan(
style: composingStyle,
text: value.composing.isValid && !value.composing.isCollapsed
? value.composing.textInside(value.text)
: "",
),
TextSpan(text: value.composing.textAfter(value.text)),
]);
}
}
application : On the initialization page or view initState add to
// Initialization property
String lastInput = "";
ChangeTextEditingController controller;
@override
void initState() {
super.initState();
controller = ChangeTextEditingController.fromValue(
TextEditingValue(
text: widget.defaultContent,
selection: TextSelection.fromPosition(
TextPosition(
affinity: TextAffinity.downstream,
offset: widget.defaultContent.length),
),
),
);
controller.addListener(() {
if (lastInput != controller.completeText) {
lastInput = controller.completeText;
/// notice onChanged Callback .
_onChange(controller.completeText);
}
});
}
边栏推荐
- [leetcode] 2. Add two numbers - go language problem solving
- What are the important trends revealed by the release of "operator data viability index"?
- "Nowadays, more than 99.9% of the code is garbage!"
- Research 280+ documents! The team of Tsinghua Huang Gao, the winner of CVPR best paper, proposed the first dynamic network overview to comprehensively review the development of dynamic networks!
- Detailed explanation of manually writing servlet in idea
- C traps and defects Chapter 2 lexical "traps" 2.4 switch statements
- Deamnet|filenotfounderror: [winerror 3] the system cannot find the specified path.: '/ Datasettest\\Set12‘
- Win10 configuring CUDA and cudnn
- R language uses logistic regression, ANOVA, outlier analysis and visual classification iris iris data set
- ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
猜你喜欢
![Simulation Implementation of [STL] string class](/img/be/2e4f8dd7da59753e109b38fdf51fba.png)
Simulation Implementation of [STL] string class

VRRP virtual redundancy protocol configuration

Vs2019 configuring Qt5 development environment
![[programmer interview classic] 01.09 string rotation](/img/d2/7ea9351c31af01665d86f8c6bc3468.png)
[programmer interview classic] 01.09 string rotation

Use Fiddler to capture apps
![ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience](/img/26/18fd3106f887f503479f081e29dac3.jpg)
ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience

An article explains unsupervised learning in images in detail

See you in Suzhou! "Cloud Intelligence Technology Forum - industry special" will be held soon

Apk packaging process

What do growth enterprises need most to build a data-driven organization?
随机推荐
Jenkins configuration plug-in interface displays "suggestions collection" in Chinese
Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!
How to judge which star you look like?
Management mode of agricultural science data center based on life cycle theory
Peripherals: timer, watchdog and RTC
R language uses logistic regression, ANOVA, outlier analysis and visual classification iris iris data set
Using multithreaded execution method in Lua script based on nlua implementation
Unable to display spline in UE4 (unreal engine4) terrain editing tool
Origin and development of philosophy Hegel external historical form
Focus on improving women's and children's sense of gain, happiness and security! In the next ten years, Guangzhou Women's and children's undertakings will make such efforts
Jedispoolconfig parameter configuration from the perspective of source code
Jsonp solves cross domain plug-ins (JS, TS)
YuQue - a useful tool for document writing and knowledge precipitation
Failed to create data snapshot: lock file [/siyuan/data/assets/image- 2022070216332-jijwccs.png failed: open /siyuan/data/assets/image- 2022070216332-jijwccs.png: permission denied; unable to lock fil
Redis tutorial
HAC cluster is modified to stand-alone
SetTimeout parameters [easy to understand]
BMW I3 based on clar architecture is not a simple "oil to electricity" product
POM reports an error
C traps and defects Chapter 2 lexical "traps" 2.4 switch statements