How to Check If 2 Lists are Equal in Dart?
A List is a collection of elements, where each element is identified by an index. The List type represents a sequence of values, where each value can be accessed using its corresponding index. Lists are created using the [] operator, and the elements in the list are separated by commas. Lists can be initialized with any type of data, including null values.
The == operator can be used to compare two values of 2 variables for equality. However, this doesn’t work with List.
import 'package:flutter/foundation.dart'; List<int> list1 = [0, 3, 6, 9]; List<int> list2 = [0, 3, 6, 9]; print(listEquals(list1, list2)); //true List<int> list1 = [0, 3, 6, 9]; List<int> list2 = [3, 0, 6, 9]; print(listEquals(list1, list2)); //false