Skip to content

Instantly share code, notes, and snippets.

@LeBaleiro
Created October 12, 2022 20:06
Show Gist options
  • Save LeBaleiro/08c8474ad5168a36cab7dce4e7faeca5 to your computer and use it in GitHub Desktop.
Save LeBaleiro/08c8474ad5168a36cab7dce4e7faeca5 to your computer and use it in GitHub Desktop.
Dart Maps
import 'package:flutter_test/flutter_test.dart';
void main() {
test('should edit the original map as default', () {
final mockMap = {"item1": "value1"};
expect(mockMap, {"item1": "value1"});
removeFirstItemFromOriginalMap(mockMap);
expect(mockMap, {});
});
test('should create a new reference and shouldn\'t edit the original map',
() {
final mockMap = {"item1": "value1"};
expect(mockMap, {"item1": "value1"});
dontRemoveFirstItemFromOriginalList(mockMap);
expect(mockMap, {"item1": "value1"});
});
}
void removeFirstItemFromOriginalMap(Map<String, String> mapParam) {
mapParam.remove("item1");
}
void dontRemoveFirstItemFromOriginalList(Map<String, String> mapParam) {
final newMapReference = Map.fromEntries(mapParam.entries);
newMapReference.remove("item1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment