Skip to content

Instantly share code, notes, and snippets.

@artem-zaitsev
Created December 21, 2022 17:20
Show Gist options
  • Save artem-zaitsev/ef0b8f7aa877a44a178a5fb225e34fdd to your computer and use it in GitHub Desktop.
Save artem-zaitsev/ef0b8f7aa877a44a178a5fb225e34fdd to your computer and use it in GitHub Desktop.
Mutable problem
import 'dart:math';
void main() {
final origin = Mutable()..name = "Origin"..numbers = [1,2,3];
/// Imagine this is navigation from screen to screen
viewOrigin(origin);
viewWithShuffle(origin);
viewChangedName(origin);
viewOrigin(origin);
}
/// Screen with origin objetc
void viewOrigin(Mutable m) {
print(
"""
Origin is: $m
"""
);
}
void viewWithShuffle(Mutable m) {
m.numbers.shuffle();
print(
"""
WithShuffle is: $m
"""
);
}
void viewChangedName(Mutable m) {
m.name = "${Random().nextInt(100)} name ${ Random().nextInt(100)}";
print(
"""
ChangedName is: $m
"""
);
}
class Mutable {
String? name;
List<int> numbers = [];
String toString() => """
Mutable: $hashCode,
name: $name,
numbers: ${numbers.join(",")}
""";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment