如何在flutter中替换多个文本?

Axe*_*ngs 5 text dart flutter

我想使用 Replaceall 方法替换从 flutter 中的文本字段获取的多个字符。我怎样才能正确实现它。\nIv\'e 尝试按如下方式执行此操作,但它不会替换字符。

\n\n
_textSelect(String str){\n    str=str.replaceAll(\'e\', \'\xc3\xa9\');\n    str=str.replaceAll(\'i\', \'I\');\n    str=str.replaceAll(\'b\', \'*\');\n    str=str.replaceAll(\'v\', \'<\');\n\n    return str;\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

语境

\n\n
Widget build(BuildContext context) {\n            return Scaffold(\n              appBar: AppBar(\n                title: Text(\'Retrieve Text Input\'),\n              ),\n              body: Padding(\n                padding: const EdgeInsets.all(16.0),\n                child: TextField(\n                  controller: myController,\n                ),\n              ),\n              floatingActionButton: FloatingActionButton(\n                // When the user presses the button, show an alert dialog containing\n                // the text that the user has entered into the text field.\n                onPressed: () {\n                  _textSelect(myController.text);//update\n                  return showDialog(\n                    context: context,\n                    builder: (context) {\n                      return AlertDialog(\n                        // Retrieve the text the that user has entered by using the\n                        // TextEditingController.\n                        content: Text(\n                        str,\n                        style:TextStyle(\n                          fontSize:50,\n                          fontFamily:"Italy"),),\n                      );\n                    },\n                  );\n                },\n                tooltip: \'Show me the value!\',\n                child: Icon(Icons.text_fields),\n              ),\n            );\n          }\n
Run Code Online (Sandbox Code Playgroud)\n

Cop*_*oad 3

我不擅长RegExp,所以也许有更好的方法。

\n\n
String _textSelect(String str) {\n  str = str.replaceAll('e', '\xc3\xa9');\n  str = str.replaceAll('i', 'I');\n  str = str.replaceAll('b', '*');\n  str = str.replaceAll('v', '<');\n  return str;\n}\n\n\nString output = _textSelect('English is blowing vhistle?'); \n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

编辑:

\n\n
final myController = TextEditingController();\nString str = '';\n\nString _textSelect(String str) {\n  str = str.replaceAll('e', '\xc3\xa9');\n  str = str.replaceAll('i', 'I');\n  str = str.replaceAll('b', '*');\n  str = str.replaceAll('v', '<');\n  return str;\n}\n\n@override\nWidget build(BuildContext context) {\n  return Scaffold(\n    appBar: AppBar(\n      title: Text('Retrieve Text Input'),\n    ),\n    body: Padding(\n      padding: const EdgeInsets.all(16.0),\n      child: TextField(\n        controller: myController,\n      ),\n    ),\n    floatingActionButton: FloatingActionButton(\n      // When the user presses the button, show an alert dialog containing\n      // the text that the user has entered into the text field.\n      onPressed: () {\n        str = _textSelect(myController.text); //update\n        return showDialog(\n          context: context,\n          builder: (context) {\n            return AlertDialog(\n              // Retrieve the text the that user has entered by using the\n              // TextEditingController.\n              content: Text(\n                str,\n                style: TextStyle(fontSize: 50, fontFamily: 'Italy'),\n              ),\n            );\n          },\n        );\n      },\n      tooltip: 'Show me the value!',\n      child: Icon(Icons.text_fields),\n    ),\n  );\n}\n
Run Code Online (Sandbox Code Playgroud)\n