题意:

如何在 Flutter 的 TextField 中禁用智能标点符号,当字符串包含撇号(')时出现的问题

问题背景:

Am encountering a problem when a string contains an apostrophe (single quote). Am developing a vocabulary learning app (French / English). The user must answer quizzes. The phone tells the user if what he/she types is the correct translation. Whenever there is an apostrophe, the string is not recognized.

我在遇到一个问题,当字符串包含撇号(单引号)时出现问题。我正在开发一个词汇学习应用(法语/英语)。用户必须回答测验。手机会告诉用户他/她输入的是否是正确的翻译。每当字符串中有撇号时,该字符串就无法被识别。

Ex : "A blade of grass" : "un brin d'herbe" / "A beehive" : "Un nid d'abeilles".

To check the answer, I split the chain into a list : [un,nid,d'abeilles] Even if the user types "d'abeilles", it's never recognized as correct.

为了检查答案,我将字符串分割成一个列表: [un, nid, d'abeilles] 即使用户输入 "d'abeilles",它也永远不会被识别为正确的。

I noticed the same problem with the speech to text functionality : if the user says the word "s'habiller" (to get dressed), it is never found by my search function.

我注意到语音转文本功能也有同样的问题:如果用户说出单词 "s'habiller"(穿衣服),我的搜索功能永远找不到它。

Anyone sees why this happens ? Would it be a "flutter" bug ?

有人知道为什么会发生这种情况吗?这会是一个 "flutter" 的 bug 吗?

In the app, I have a wordbank which was created with Microsoft Excel and then imported into visual studio. The wordbank is made up of WORD objects that have a series of parameters. Here is the one for blade of grass.

在应用中,我有一个词库,它是通过 Microsoft Excel 创建的,然后导入到 Visual Studio 中。词库由一系列具有多个参数的 WORD 对象组成。以下是 "blade of grass" 的词条。

Word(
    id: 37,
    level: 6,
    main: "blade of grass",
    mainFr: "brin d'herbe",
    theme: [
      T(
          e: "house",
          f: "maison",
          ste: ["in the garden"],
          stf: ["dans le jardin"]),
      T(
          e: "nature",
          f: "nature",
          ste: ["in the meadow"],
          stf: ["dans la prairie"])
    ],
    articleEng: "a",
    articleFr: "un",
    nature: "noun",
    plur: "blades of grass ",
    ortho2: "",
    phon: "ˈbleɪd əv ˈgrɑːs",
    son: "",
    remPhon: "",
    french: [],
    syn: [],
    ant: [],
    wDef: "a single thin flat piece of grass.",
    wPhrase: "There was no wind at all. Not a leaf or blade of grass moved.",
    wPhraseFr:
        "Il n'y avait pas de vent du tour. Pas une feuille ni un brin d'herbe ne bougeait.",
    past: [],
    idiomsEn: [],
    idiomsFr: [],
    marqueur: "",
    remarque: "",
  ),

问题解决:

I finally found the solution for this problem. It was indeed created with Apple's implementation of SMART PUNCTUATION. It is easy to disable it when using a textfield :

我终于找到了解决这个问题的方法。确实是由于苹果的智能标点(SMART PUNCTUATION)功能造成的。当使用文本框时,禁用它是很容易的:

TextFormField(
     smartQuotesType: SmartQuotesType.disabled,

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐