当前位置:网站首页>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);
}
});
}
边栏推荐
- KVM virtualization jobs
- 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
- Data integration | what are the tools for data integration at home and abroad?
- Management mode of agricultural science data center based on life cycle theory
- Hbuilderx developed by uni app connects to night God simulator
- Use Fiddler to capture apps
- How MySQL 8.0 based on TRX_ Id find the statement of the whole transaction
- Anacona has too many environments?? How to view your current environment in jupyter
- EasyX realizes button effect
- POM reports an error
猜你喜欢

Solution to the occupation of project startup port

July 8, 2022
![[programmer interview classic] 01.09 string rotation](/img/d2/7ea9351c31af01665d86f8c6bc3468.png)
[programmer interview classic] 01.09 string rotation

Using multithreaded execution method in Lua script based on nlua implementation

How can arm access the Internet through a laptop?

Detailed explanation of manually writing servlet in idea

Cloud native platform, let edge applications play out!

Why can't reading more books improve your writing?

Google launched another "man grabbing war" for core making, and Intel's 17 year veteran joined!

Today in history: the kotlin language was published for the first time; The father of the IMAP agreement was born; CT imaging achieves a new breakthrough
随机推荐
Open sharing of scientific data in the context of open science: the practice of the national Qinghai Tibet Plateau scientific data center
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!
Use Fiddler to capture apps
Anacona has too many environments?? How to view your current environment in jupyter
Can PostgreSQL CDC only connect to the main database? Connection from the library reports an error logical decoden
BMW I3 based on clar architecture is not a simple "oil to electricity" product
Dynamic memory development
Detailed explanation of the principles and differences between static pages and dynamic pages
MySQL advanced (13) command line export import database
Talk about resume optimization and interview skills of algorithm post!
Inventory of well-known source code mall systems at home and abroad
Android memory optimized disk cache
Data integration | what are the tools for data integration at home and abroad?
[hero planet July training leetcode problem solving daily] 20th BST
VRRP virtual redundancy protocol configuration
When does MySQL use table locks and row locks?
How MySQL 8.0 based on TRX_ Id find the statement of the whole transaction
Gerrit statistics script
Detailed explanation of manually writing servlet in idea
KVM virtualization jobs