List equality works differently in Dart. Since everything is an object you need a mechanism to check each element.
You can use either the ListEquality
class to compare two lists if they do not have nested objects/informations or, if you want to compare nested objects/informations you can use DeepCollectionEquality
. Both come from collections library which comes out of the box with Dart.
You can check the following examples of the usages:
import 'package:collection/collection.dart';
void main() {
const numberListOne = [1,2,3];
const numberListTwo = [1,2,3];
final _listEquality = ListEquality();
print(_listEquality.equals(numberListOne, numberListTwo));
}
expect
implicitly uses theequals
matcher, and theequals
matcher checks forList
s and performs an element-wise comparison for equality.