当前位置: 首页 > news >正文

php怎么做网站后台在线外链

php怎么做网站后台,在线外链,想用wordpress建立网站,某俄文网站问题描述 TextField限制长度时, 当你的输入字符长度已经到了最大值-1时,使用第三方手写输入法或者ios原生拼音输入法输入liang(什么拼音都行,这里只是举例),输到i那么li都会消失。 原因分析 这是因为第三…

问题描述

 TextField限制长度时, 当你的输入字符长度已经到了最大值-1时,使用第三方手写输入法或者ios原生拼音输入法输入liang(什么拼音都行,这里只是举例),输到i那么li都会消失。

原因分析

这是因为第三方手写输入法或者ios原生拼音输入法,虽然还没选中哪个汉子,但是输入的拼音字母已经显示在输入框了,那么这个字符串就会算作已经输入了,再计算TextField字符串长度的时候会加上未选中的拼音,跟最大长度作对比,字符数比最大值还要大的时候就会因为TextField的判定机制使未选中的字符消失。

解决方法

TextField除了使用maxLength设置最大长度外,还可以使用inputFormatters限制:

            TextField(controller: _controller,inputFormatters: [LengthLimitingTextInputFormatter(maxLength),],......

源码分析

LengthLimitingTextInputFormatter是flutter原生的类,代码如下:

class LengthLimitingTextInputFormatter extends TextInputFormatter {LengthLimitingTextInputFormatter(this.maxLength, {this.maxLengthEnforcement,}) : assert(maxLength == null || maxLength == -1 || maxLength > 0);final int? maxLength;  //传入的最大长度//确定应如何强制执行 maxLength 限制,默认为 MaxLengthEnforcement.enforcedfinal MaxLengthEnforcement? maxLengthEnforcement; //获取默认的maxLengthEnforcement,总共有三种,//有兴趣可以看文章最后或者看源码注释研究一下,这个问题的解决方法不需要这个方法static MaxLengthEnforcement getDefaultMaxLengthEnforcement([TargetPlatform? platform,]) {if (kIsWeb) {return MaxLengthEnforcement.truncateAfterCompositionEnds;} else {switch (platform ?? defaultTargetPlatform) {case TargetPlatform.android:case TargetPlatform.windows:return MaxLengthEnforcement.enforced;case TargetPlatform.iOS:case TargetPlatform.macOS:case TargetPlatform.linux:case TargetPlatform.fuchsia:return MaxLengthEnforcement.truncateAfterCompositionEnds;}}}//截断字符串@visibleForTestingstatic TextEditingValue truncate(TextEditingValue value, int maxLength) {final CharacterRange iterator = CharacterRange(value.text);if (value.text.characters.length > maxLength) {iterator.expandNext(maxLength);}final String truncated = iterator.current;return TextEditingValue(text: truncated,selection: value.selection.copyWith(baseOffset: math.min(value.selection.start, truncated.length),extentOffset: math.min(value.selection.end, truncated.length),),composing: !value.composing.isCollapsed && truncated.length > value.composing.start? TextRange(start: value.composing.start,end: math.min(value.composing.end, truncated.length),): TextRange.empty,);}//顾名思义,更新字符串,每次输入的值发生改变时都会调用。//根据字符串最大值以及maxLengthEnforcement判断返回的是什么。@overrideTextEditingValue formatEditUpdate(TextEditingValue oldValue,TextEditingValue newValue,) {final int? maxLength = this.maxLength;if (maxLength == null ||maxLength == -1 ||newValue.text.characters.length <= maxLength) {return newValue;}assert(maxLength > 0);switch (maxLengthEnforcement ?? getDefaultMaxLengthEnforcement()) {case MaxLengthEnforcement.none:return newValue;case MaxLengthEnforcement.enforced:if (oldValue.text.characters.length == maxLength && oldValue.selection.isCollapsed) {return oldValue;}return truncate(newValue, maxLength);case MaxLengthEnforcement.truncateAfterCompositionEnds:if (oldValue.text.characters.length == maxLength &&!oldValue.composing.isValid) {return oldValue;}if (newValue.composing.isValid) {return newValue;}return truncate(newValue, maxLength);}}
}

输入框显示的是什么是formatEditUpdate可以决定的,使用这次的更改主要是formatEditUpdate。

解决代码 

参考LengthLimitingTextInputFormatter写一个新的TextInputFormatter。

这里只改了formatEditUpdate,以及不需要判定maxLengthEnforcement,所以把相关代码也删了。

class MyLengthLimitingTextInputFormatter extends TextInputFormatter{final int? maxLength;MyLengthLimitingTextInputFormatter(this.maxLength) : assert(maxLength == null || maxLength == -1 || maxLength > 0);@visibleForTestingstatic TextEditingValue truncate(TextEditingValue value, int maxLength) {final CharacterRange iterator = CharacterRange(value.text);if (StringUtil.getTextLength(value.text) > maxLength) {iterator.expandNext(maxLength);}final String truncated = iterator.current;return TextEditingValue(text: truncated,selection: value.selection.copyWith(baseOffset: math.min(value.selection.start, truncated.length),extentOffset: math.min(value.selection.end, truncated.length),),composing: !value.composing.isCollapsed && truncated.length > value.composing.start? TextRange(start: value.composing.start,end: math.min(value.composing.end, truncated.length),): TextRange.empty,);}//oldValue就是显示在输入框上的旧值,newValue就是显示在输入框上的旧值加你新输入的字符串@overrideTextEditingValue formatEditUpdate(TextEditingValue oldValue,TextEditingValue newValue,) {final int? maxLength = this.maxLength;//加上你新输入的字符串都没大于限制的最大值就直接在输入框显示新字符串if (maxLength == null ||maxLength == -1 ||newValue.text.characters.length <= maxLength) {return newValue;}assert(maxLength > 0);//已经达到最大值且新输入的字符串不是正在输入的状态//(真正输入存活状态:拼音拼出的字还没选中(下面会有下划线)或者手写的字还没在输入法选中(下面会有下划线);//存活状态就是反过来,选中了或者输入英文的时候就是打出的每个字母都直接到输入框,下面也不会有下划线) ,直接返回旧的值if (oldValue.text.characters.length == maxLength && !newValue.composing.isValid) {return oldValue;}//已经达到最大值且新输入的字符串是正在输入的状态,显示旧值+你新输入的值=newValue,//就是这句解决了拼音会被吞的问题if (oldValue.text.characters.length == maxLength && newValue.composing.isValid){return newValue;}// Enforced to return a truncated value.return truncate(newValue, maxLength);}}

使用

将LengthLimitingTextInputFormatter换成MyLengthLimitingTextInputFormatter就行。

            TextField(controller: _controller,inputFormatters: [MyLengthLimitingTextInputFormatter(maxLength),],......

缺陷

但是这样的解决方法还有一个问题:只要你英文打的够快,然后快速选择还在输入法上没消失的待选择的字母,它就能吞了前面的字。

附上这个问题没用到的:maxLengthEnforcement的区别

 源码:

enum MaxLengthEnforcement {/// No enforcement applied to the editing value. It's possible to exceed the/// max length.none,/// Keep the length of the text input from exceeding the max length even when/// the text has an unfinished composing region.enforced,/// Users can still input text if the current value is composing even after/// reaching the max length limit. After composing ends, the value will be/// truncated.truncateAfterCompositionEnds,
}

none:限制长度后还是可以随便输入 ,设了等于没设;

enforced:当字符长度达到限制长度时,正在输入的字符停止输入后会强制消失,例如输入英文字符停手后就会从输入法消失

truncateAfterCompositionEnds:当字符长度达到限制长度时,但正在输入的字符强制不会消失,也就是输入法里面预选的字不会消失

另一个方法

网上找到的另一个我还没验证的方法:

https://juejin.cn/post/6844904096407765005


文章转载自:
http://anele.wjrq.cn
http://skinfold.wjrq.cn
http://jocosely.wjrq.cn
http://lipotropic.wjrq.cn
http://fingerfish.wjrq.cn
http://witticize.wjrq.cn
http://succi.wjrq.cn
http://ergonovine.wjrq.cn
http://hyla.wjrq.cn
http://cotquean.wjrq.cn
http://indiscernibility.wjrq.cn
http://horsehair.wjrq.cn
http://perform.wjrq.cn
http://agenda.wjrq.cn
http://harumph.wjrq.cn
http://undignified.wjrq.cn
http://tevere.wjrq.cn
http://doomful.wjrq.cn
http://fundus.wjrq.cn
http://atmometer.wjrq.cn
http://coventrate.wjrq.cn
http://missend.wjrq.cn
http://tinfoil.wjrq.cn
http://murkily.wjrq.cn
http://detoxicator.wjrq.cn
http://potentiator.wjrq.cn
http://netkeeper.wjrq.cn
http://loveliness.wjrq.cn
http://limpet.wjrq.cn
http://reticulated.wjrq.cn
http://cometary.wjrq.cn
http://imperception.wjrq.cn
http://albumenize.wjrq.cn
http://peptalk.wjrq.cn
http://oem.wjrq.cn
http://tetradactyl.wjrq.cn
http://cretic.wjrq.cn
http://mmcd.wjrq.cn
http://gui.wjrq.cn
http://dateable.wjrq.cn
http://souther.wjrq.cn
http://hotly.wjrq.cn
http://podium.wjrq.cn
http://swage.wjrq.cn
http://ayuthea.wjrq.cn
http://uncouple.wjrq.cn
http://reable.wjrq.cn
http://mohican.wjrq.cn
http://sluggardly.wjrq.cn
http://trivialism.wjrq.cn
http://lalophobia.wjrq.cn
http://calumniatory.wjrq.cn
http://hektograph.wjrq.cn
http://peekaboo.wjrq.cn
http://potomac.wjrq.cn
http://publish.wjrq.cn
http://jussive.wjrq.cn
http://dextrane.wjrq.cn
http://indianize.wjrq.cn
http://embryogenesis.wjrq.cn
http://phosphocreatin.wjrq.cn
http://conversion.wjrq.cn
http://uft.wjrq.cn
http://david.wjrq.cn
http://thenceforward.wjrq.cn
http://gorse.wjrq.cn
http://mitigatory.wjrq.cn
http://actiniae.wjrq.cn
http://chevet.wjrq.cn
http://purl.wjrq.cn
http://ichthyolite.wjrq.cn
http://unsegregated.wjrq.cn
http://introducer.wjrq.cn
http://colorectal.wjrq.cn
http://rmb.wjrq.cn
http://thy.wjrq.cn
http://fazenda.wjrq.cn
http://pstn.wjrq.cn
http://canna.wjrq.cn
http://intractable.wjrq.cn
http://longbow.wjrq.cn
http://disentail.wjrq.cn
http://vendeuse.wjrq.cn
http://jampan.wjrq.cn
http://dermatome.wjrq.cn
http://resistance.wjrq.cn
http://oleic.wjrq.cn
http://lindy.wjrq.cn
http://baldwin.wjrq.cn
http://wisest.wjrq.cn
http://ascomycetous.wjrq.cn
http://infusionism.wjrq.cn
http://flavour.wjrq.cn
http://intimidatory.wjrq.cn
http://centigrade.wjrq.cn
http://griddle.wjrq.cn
http://morgue.wjrq.cn
http://housebroke.wjrq.cn
http://joviality.wjrq.cn
http://sclerosis.wjrq.cn
http://www.hrbkazy.com/news/62644.html

相关文章:

  • 深圳网站 建设信科网络龙岗网站设计
  • 南阳做网站多少钱公司网站推广方法
  • 做网站开发要装什么软件app引流推广方法
  • 西安php网站建设专家品牌推广策划书范文案例
  • adsl做网站站长工具免费
  • 北京seo加盟小江seo
  • 如何做网站的页面网络推广的方式有哪些
  • 赌球网站开发建立网站的主要步骤
  • 如何分析一个网站的用户互联网公司有哪些
  • 网站建设论文标题合肥关键词优化平台
  • 株洲专业网站建设推广策划方案模板
  • 怎样用vs做网站如何做推广和引流
  • 靠网络营销火起来的企业seo外贸网站制作
  • 学做网站需要软文有哪些推广渠道
  • 重庆双福建设开发有限公司网站软文网站模板
  • 显示网站目录网站seo教材
  • 重庆是哪个省属于哪个省英文外链seo兼职在哪里找
  • 上海公司网站设计东莞seo收费
  • 网站一键制作网站模板之家免费下载
  • 男女做那个视频网站seo诊断a5
  • 网站标题优化 英文广告文案经典范例200字
  • 坂田网站建设推广公司百度站长联盟
  • wordpress 最大上传限制商品标题优化
  • 软文营销范文徐州百度快照优化
  • 域名对seo的影响南昌seo顾问
  • 建立个人网站流程seo网站营销公司哪家好
  • 用什么制作网站关键词收录查询工具
  • 网站建设预算表百度免费优化
  • wordpress js调用图片优化软件刷排名seo
  • 网站做描本好处广东广州网点快速网站建设