Note Widgets
As a final step, we're going to create a couple of widgets for the note feature:
A list tile that displays a note entry and navigates to the NoteEntryFormPage when tapped.
A widget for streaming the 10 most recent notes.
A widget for displaying a list of notes in a paginated manner.
A page that allows the user to create, update and delete a note entry.
The main page for the note feature showcasing the StreamNotesListView, PaginatedNotesListView and a floating action button for creating a new note entry.
1. Widgets
In the note_app/modules/presentation/lib/note/widgets/ directory, create the following files:
1.1. Create the NoteEntryListTile
Make a file named note_entry_list_tile.dart and paste the code below:
import 'package:domain/note/entities/note_entry.dart';
import 'package:flutter/material.dart';
import 'package:presentation/note/pages/note_entry_form_page.dart';
/// {@template NoteEntryListTile}
/// A [ListTile] that displays a [NoteEntry] and navigates to the
/// [NoteEntryFormPage] when tapped.
/// {@endtemplate}
class NoteEntryListTile extends StatelessWidget {
/// {@macro NoteEntryListTile}
const NoteEntryListTile({super.key, required this.noteEntry});
/// The [NoteEntry] to display.
final NoteEntry noteEntry;
@override
Widget build(BuildContext context) {
return ListTile(
key: ValueKey(noteEntry.id),
title: Text(noteEntry.title.isEmpty ? 'No title' : noteEntry.title),
subtitle:
Text(noteEntry.content.isEmpty ? 'No content' : noteEntry.content),
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => NoteEntryFormPage(noteEntry: noteEntry),
),
),
);
}
}1.2. Create the StreamNotesListView
Make a file named stream_notes_list_view.dart and paste the code below:
1.3. Create the PaginatedNotesListView
Make a file named paginated_notes_list_view.dart and paste the code below:
2. Pages
In the note_app/modules/presentation/lib/note/pages/ directory, create the following files:
2.1. Create the NoteEntryFormPage
Make a file named note_entry_form_page.dart and paste the code below:
2.2. Create the HomePage
Make a file named home_page.dart and paste the code below:
Once all widgets are created, you're done! 🎉
Last updated