1+ import 'package:built_collection/built_collection.dart' ;
2+ import 'package:collection/collection.dart' ;
3+
14import '../domain/contact.dart' ;
25import '../domain/contact_repository.dart' ;
36import 'local/dao/contact_dao.dart' ;
@@ -9,39 +12,36 @@ class ContactRepositoryImpl implements ContactRepository {
912 const ContactRepositoryImpl (this ._contactDao);
1013
1114 @override
12- Stream <List <Contact >> search ({String query = '' }) {
13- return _contactDao.search (query).map ((entities) {
14- return entities.map (_toContact).toList (growable: false );
15- });
15+ Stream <BuiltList <Contact >> search ({required String by}) {
16+ return _contactDao.search (by).map (
17+ (entities) => entities.map (_toContact).whereNotNull ().toBuiltList ());
1618 }
1719
1820 @override
19- Stream <Contact > getContactById (int id) {
20- return _contactDao.findById (id).map (_toContact);
21- }
21+ Stream <Contact ?> getContactById (int id) =>
22+ _contactDao.findById (id).map (_toContact);
2223
2324 @override
24- Future <bool > delete (Contact contact) {
25- return _contactDao.deleteById (contact.id);
26- }
25+ Future <bool > delete (Contact contact) => _contactDao
26+ .deleteById (ArgumentError .checkNotNull (contact.id, 'Contact id' ));
2727
2828 @override
29- Future <bool > insert (Contact contact) {
30- return _contactDao.insert (_toEntity (contact));
31- }
29+ Future <bool > insert (Contact contact) =>
30+ _contactDao.insert (_toEntity (contact));
3231
3332 @override
34- Future <bool > update (Contact contact) {
35- return _contactDao.update (_toEntity (contact));
36- }
33+ Future <bool > update (Contact contact) =>
34+ _contactDao.update (_toEntity (contact));
3735
3836 @override
39- Future <void > deleteAll () {
40- return _contactDao.deleteAll ();
41- }
37+ Future <void > deleteAll () => _contactDao.deleteAll ();
4238}
4339
44- Contact _toContact (ContactEntity entity) {
40+ Contact ? _toContact (ContactEntity ? entity) {
41+ if (entity == null ) {
42+ return null ;
43+ }
44+
4545 return Contact (
4646 (b) => b
4747 ..id = entity.id
0 commit comments