Created
December 21, 2022 17:20
-
-
Save artem-zaitsev/ef0b8f7aa877a44a178a5fb225e34fdd to your computer and use it in GitHub Desktop.
Mutable problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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