如何在Dart中创建一个空列表 [英] How to create an empty list in Dart
本文介绍了如何在Dart中创建一个空列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为Flutter项目创建一个空列表.
I want to create an empty list for a Flutter project.
final prefs = await SharedPreferences.getInstance();
final myStringList = prefs.getStringList('my_string_list_key') ?? <empty list>;
我似乎记得有多种方法,但有一种推荐的方法.我该怎么办?
I seem to remember there are multiple ways but one recommended way. How do I do it?
推荐答案
有几种方法可以在Dart中创建空列表:
There are a few ways to create an empty list in Dart:
[]
List()
<String>[]
List<String>()
但是,有效《 Dart使用指南》 建议这样做:
[]
或者如果您需要指定类型,则此:
Or if you need to specify the type, then this:
<String>[]
这篇关于如何在Dart中创建一个空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文