有时候在Flutter的Text小部件中需要使用非断行空格,例如,“显示更多”链接或带单位的数值如“50 km/h”。
以下代码可以正常工作但看起来过于复杂:
const int $nbsp = 0x00A0; // from https://pub.dev/packages/charcode
print('Hello${String.fromCharCode($nbsp)}World'); // --> prints "Hello World", does not break
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :/
我想知道在插值字符串中是否有更短的方式使用charcode包中的整数常量?
String.fromCharCode
是预期的使用方式,你可以在几天后将您的评论发布为答案,我会很乐意接受它。 - RobDil