step-15
This commit is contained in:
parent
79202e0328
commit
94b65f952b
|
@ -12,11 +12,16 @@ class NotesService {
|
|||
List<DatabaseNote> _notes = [];
|
||||
|
||||
static final NotesService _shared = NotesService._sharedInstance();
|
||||
NotesService._sharedInstance();
|
||||
NotesService._sharedInstance() {
|
||||
_notesStreamController = StreamController<List<DatabaseNote>>.broadcast(
|
||||
onListen: () {
|
||||
_notesStreamController.sink.add(_notes);
|
||||
},
|
||||
);
|
||||
}
|
||||
factory NotesService() => _shared;
|
||||
|
||||
final _notesStreamController =
|
||||
StreamController<List<DatabaseNote>>.broadcast();
|
||||
late final StreamController<List<DatabaseNote>> _notesStreamController;
|
||||
|
||||
Stream<List<DatabaseNote>> get allNotes => _notesStreamController.stream;
|
||||
|
||||
|
|
|
@ -21,12 +21,6 @@ class _NotesViewState extends State<NotesView> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_notesService.close();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -75,7 +69,25 @@ class _NotesViewState extends State<NotesView> {
|
|||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.waiting:
|
||||
case ConnectionState.active:
|
||||
return const Text('Waiting for all notes...');
|
||||
if (snapshot.hasData) {
|
||||
final allNotes = snapshot.data as List<DatabaseNote>;
|
||||
return ListView.builder(
|
||||
itemCount: allNotes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final note = allNotes[index];
|
||||
return ListTile(
|
||||
title: Text(
|
||||
note.text,
|
||||
maxLines: 1,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
default:
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue