Sitemap

Dart List — Code Snippets Part 1

3 min readMay 17, 2021

--

Press enter or click to view image in full size

This article will give you the most important List Code Snippets. The full documentation can be found from api.flutter.dev website.

What is List in Dart?

An indexable collection of objects with a length is called List.

Dart List having commonly have two different type kinds.

  1. Fixed length — The Dart will give you an error when you try to change the length of the list.
  2. Dynamic length (growable length)

Okay. Lets jump in to the code snipits.

Constructors

  1. List.empty({bool growable: false})
Press enter or click to view image in full size

2. List.filled(int length, E fill, {bool growable: false})

Press enter or click to view image in full size

3. List.from(Iterable elements, {bool growable: true})

Press enter or click to view image in full size

4. List.generate(int length, E generator(int index), {bool growable: true})

Press enter or click to view image in full size

5. List.unmodifiable(Iterable elements)

Press enter or click to view image in full size

Properties

  1. first
Press enter or click to view image in full size

2. isEmpty

Press enter or click to view image in full size

3. last

Press enter or click to view image in full size

4. reversed

Press enter or click to view image in full size

5. length

Press enter or click to view image in full size

Conclusion

I hope this article will help you to quickly understand and get to know about constructors and the properties of List. The Part 2 will contain the methods of List. Once the Part 2 get published this article will be updated soon.

This Code Snippets can be found from GitHub: https://github.com/Achsuthan/FlutterCodeSnippets/tree/main/DartList

Thanks for reading this article. Please leave claps if you find it useful! And I will be happy to hear any feedback.

Follow me on LinkedIn: www.linkedin.com/in/achsuthanmahendran

--

--

Achsuthan Mahendran
Achsuthan Mahendran

Written by Achsuthan Mahendran

iOS Developer, Web Developer, Flutter Developer. GitHub: achsuthan