Last active
November 2, 2020 06:47
-
-
Save chimon2000/edb85b52005901db927bd0fd96d7db21 to your computer and use it in GitHub Desktop.
state_examples: common classes
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
// A simple helper function to allow us to immutably add to lists. | |
extension ImmutableList<T> on List<T> { | |
List<T> concat(T item) => List<T>.from(<T>[...this, item]); | |
} |
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
// A simple widget for displaying individual notes. | |
class Note extends StatelessWidget { | |
final String text; | |
const Note({Key key, this.text}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: const EdgeInsets.symmetric(vertical: 8.0), | |
child: Text('Note: $text'), | |
); | |
} | |
} |
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
// You can add equatable as a dependency to your pubspec.yaml | |
// https://pub.dev/packages/equatable/install | |
class NotesState extends Equatable { | |
final List<String> notes; | |
final String input; | |
NotesState( | |
this.notes, | |
this.input, | |
); | |
@override | |
List<Object> get props => [notes, input]; | |
@override | |
bool get stringify => true; | |
NotesState copyWith({ | |
List<String> notes, | |
String input, | |
}) { | |
return NotesState( | |
notes ?? this.notes, | |
input ?? this.input, | |
); | |
} | |
NotesState.initial() | |
: notes = [], | |
input = ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment