如何在Flutter中限制表情符号用于文本字段? [英] How to restrict emoji for textfield in flutter?

查看:1361
本文介绍了如何在Flutter中限制表情符号用于文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在寻找限制表情符号正则表达式或用于扑动的输入格式化程序. 如果有人有想法,我想在文本字段中禁用表情符号,然后请帮助我. 提前谢谢.

Hello guy i'm finding for restrict emoji regex or input formatter for flutter. i want to disable emoji in textfield if anybody have idea then please help me. Thanks In Advance.

推荐答案

@ magicleon94可以很好地回答您的问题,但是我认为我的回答值得一提,不是限制表情符号,而是根据您的要求只允许输入字符我们在flutter中内置了一个输入格式化程序,因此我们不必编写一个称为 WhitelistingTextInputFormatter()

@magicleon94 pretty much answers your question but I think my answer is worth mentioning that instead of restricting the emojis only allow the input characters as per your requirement, and luckily we have an input formatter built into flutter so we don't have to write one its called WhitelistingTextInputFormatter()

并像这样简单地使用它

@已弃用

inputFormatters: [new WhitelistingTextInputFormatter(RegExp("[a-zA-Z]")),],

在flutter v1.20.0-1.0.pre之后 "WhitelistingTextInputFormatter"已弃用,不应使用.改为使用

after flutter v1.20.0-1.0.pre the above 'WhitelistingTextInputFormatter' is deprecated and shouldn't be used. Instead Use

inputFormatters: [ FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")),],

上面的行仅允许在输入字段中输入字母,并限制所有表情符号,以确保相信我:)

The above line only allows Alphabets in the input field and restricts all emojis for sure trust me :)

这篇关于如何在Flutter中限制表情符号用于文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆