Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check two maps are equal in dart

Tags:

dart

Is it possible to check two maps are equals or not like java equals?

void main() {
  Map map1 = {'size': 38, 'color': 'red'};
  Map map2 = {'size': 38, 'color': 'red'};

  if(map1== map2){//both keys and values
    print('yes');
  }else{
    print('no');
  }
}
like image 229
BIS Tech Avatar asked May 13 '20 02:05

BIS Tech


People also ask

How do you compare two sets in darts?

setEquals<T> function Null safety Compares two sets for element-by-element equality. Returns true if the sets are both null, or if they are both non-null, have the same length, and contain the same members. Returns false otherwise. Order is not compared.

What is map () in Dart?

Dart Map is an object that stores data in the form of a key-value pair. Each value is associated with its key, and it is used to access its corresponding value. Both keys and values can be any type. In Dart Map, each key must be unique, but the same value can occur multiple times.


1 Answers

I found mapEquals.

import 'package:flutter/foundation.dart';

void main() {
  Map map1 = {'size': 38, 'color': 'red'};
  Map map2 = {'size': 38, 'color': 'red'};


  if(mapEquals(map1, map2)){
    print('yes');
  }else{
    print('no');
  }
}
like image 183
BIS Tech Avatar answered Oct 23 '22 02:10

BIS Tech