Dart| Flutter How to: Check sublist contains all elements in List

This tutorial shows how to check sublist exists in Dart or Flutter List

How to check sublist exists in a list of  Dart and Flutter

How do Check sub lists exist in a list of dart/flutter?

dart list provides multiple ways to check the sub list contains in the list of elements.

First Convert list into set using Set.of() method Check sub list exists in Set using Set.containsAll() method

Here is an example code

void main() {
  var list = [1, 4, 5, 2, 8];
  var sublist = [1, 4];
  var set = Set.of(list);

  print(set.containsAll(sublist)); //true
  print(set.containsAll([2, 3])); //false

  • using enumerable except method except for checking all the elements in the sublist that exists in a list and returning empty if found, else non-empty list.

Check isEmpty() returns true if list is empty

import 'package:enumerable/enumerable.dart';

void main() {
  var list = [1, 4, 5, 2, 8];
  var sublist = [1, 4];

  print(sublist.except(list).isEmpty); //true
  print([2, 3].except(list).isEmpty); //false


To summarize, Learn how to check the sublist contains all elements in a list dart and flutter.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.

Related posts

Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

What is the difference between var and dynamic and final in dart?| Flutter By Example

How to: Check if Phone number is valid or not in Dart| Flutter By Example

Dart| Flutter How to read an image from a disk and resize a file

Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

Dart| Flutter How to get extension name and MIME type of a file with example