Last active
April 28, 2022 19:53
-
-
Save hectorAguero/0d728272159f523cc4b624e81d51ef1f to your computer and use it in GitHub Desktop.
Dart/Flutter copyWith
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
void main() { | |
Question a = Question(title:'foo'); | |
Question b = a; | |
Question c = a.copyWith(); | |
b.title = 'bar'; | |
c.title = 'bar'; | |
print('printing question foo & bar'); | |
print('a: ' + a.title); | |
print('b: ' +b.title); | |
print('c: ' +c.title); | |
print('is a = b: ${a==b}' ); | |
print('is a = c: ${a==c}' ) ; | |
} | |
class Question{ | |
Question({required this.title}); | |
String title; | |
Question copyWith({String? title}) { | |
final answered = Question(title: title ?? this.title); | |
return answered; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment