Skip to content

Instantly share code, notes, and snippets.

@hectorAguero
Last active April 28, 2022 19:53
Show Gist options
  • Save hectorAguero/0d728272159f523cc4b624e81d51ef1f to your computer and use it in GitHub Desktop.
Save hectorAguero/0d728272159f523cc4b624e81d51ef1f to your computer and use it in GitHub Desktop.
Dart/Flutter copyWith
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