Skip to content

Instantly share code, notes, and snippets.

Last active November 2, 2020 06:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chimon2000/edb85b52005901db927bd0fd96d7db21 to your computer and use it in GitHub Desktop.
state_examples: common classes
// 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]);
// A simple widget for displaying individual notes.
class Note extends StatelessWidget {
final String text;
const Note({Key key, this.text}) : super(key: key);
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text('Note: $text'),
// You can add equatable as a dependency to your pubspec.yaml
class NotesState extends Equatable {
final List<String> notes;
final String input;
List<Object> get props => [notes, input];
bool get stringify => true;
NotesState copyWith({
List<String> notes,
String input,
}) {
return NotesState(
notes ?? this.notes,
input ?? this.input,
: notes = [],
input = '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment