You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
684 B
23 lines
684 B
4 weeks ago
|
import 'package:mustache_template/mustache.dart';
|
||
|
|
||
|
void main() {
|
||
|
final template = Template('''
|
||
|
{{#value}}Value exists: {{value}},{{/value}}
|
||
|
others...
|
||
|
''');
|
||
|
|
||
|
print(template.renderString({'value': '有内容'}));
|
||
|
|
||
|
// ✅ 正确做法1:key 完全不存在
|
||
|
print(template.renderString({'value': ''}));
|
||
|
// 输出: "No value provided"
|
||
|
|
||
|
// ✅ 正确做法2:显式设置为 null(需确保非空安全环境)
|
||
|
print(template.renderString({'value': null}));
|
||
|
// 输出: "No value provided"
|
||
|
|
||
|
// ❌ 以下会报错:
|
||
|
// print(template.renderString({'value': ''})); // 空字符串
|
||
|
// print(template.renderString({'value': 'Hello'})); // 非空字符串
|
||
|
}
|