-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_changes.patch
More file actions
5476 lines (5338 loc) · 421 KB
/
Copy pathuser_changes.patch
File metadata and controls
5476 lines (5338 loc) · 421 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/CHANGELOG.md b/CHANGELOG.md
index daba9dc..6229513 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,57 @@ All notable changes to ZooPed will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.2.0] - 2026-06-17
+
+### Added
+
+- **Litters & Offspring** - New 4th tab on Dog Profile displaying linked litters and directly-sired offspring.
+- **Dashboard Filtering** - Added comprehensive bottom sheet filters allowing A-Z, Age, Recent sorting, and Male/Female filtering.
+- **Dynamic Theming** - Replaced legacy static colors with dynamic appearance settings. Users can toggle Dark/Light mode and select from 6 premium color accents.
+- **Official Pedigree PDF** - Massively upgraded the "Share PDF" layout to an official A4 Landscape certificate containing the 3-generation visual pedigree tree and preloaded ancestral photos.
+
+### Fixed
+- **Architectural Polish** - Achieved 0 compiler warnings, permanently resolving missing BuildContext checks across deep async gaps and deprecation alerts inside forms.
+
+## [1.1.1] - 2026-06-17
+
+### Added
+
+- **Kennel Contacts** - Added specific Phone, WhatsApp, and Email fields to Kennel Profile
+- **Database Schema v6** - Migrated local database to support expanded profile fields
+
+### Fixed
+
+- **Dashboard Refresh** - Fixed an issue where the dog list wouldn't update immediately after a dog was deleted
+- **Database Size Refresh** - Added SQLite VACUUM optimization to accurately calculate and compress the database size when refreshing backups
+
+## [1.1.0] - 2026-06-17
+
+### Added
+
+- **Edit Dog Screen** - Edit existing dog profiles via `/dog/:id/edit` route
+- **Litter Browse Screen** - List all registered litters with sire/dam names and puppy counts
+- **Dog Photo Support** - Add photos to dog profiles; displayed on detail screen
+- **CSV Import Dedup** - Import validation skips duplicates by registered name and microchip
+
+### Fixed
+
+- **Pedigree Tree Performance** - Replaced N+1 recursive queries with batched ancestor loading
+- **Updated about screen logo and layout**
+
+## [1.0.1] - 2026-06-17
+
+### Added
+
+- Added Great Grandparents to the pedigree tree (5-generation display)
+
+### Fixed
+
+- Fixed pedigree tree connection wires rendering
+- Fixed duplicate dog database insertion error when adding new dogs
+- Patched a memory leak in the pedigree canvas
+- Resolved duplicate search suggestion entries
+
## [1.0.0] - 2026-06-14
### Added
diff --git a/README.md b/README.md
index fe265fc..bcdfeb7 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
A Flutter Android application for tracking dog pedigrees, designed for professional breeders and kennel clubs.
-**Package:** `com.zooped.niiabe` | **Version:** 1.0.0 | **License:** Private
+**Package:** `com.zooped.niiabe` | **Version:** 1.2.0 | **License:** Private
## Platform
@@ -21,6 +21,7 @@ A Flutter Android application for tracking dog pedigrees, designed for professio
- **Litter Tracking** - Record matings, whelping dates, and auto-create puppy profiles with inherited parentage
- **Custom Kennel Branding** - Upload kennel logo and configure breeder profile (logo-driven theme)
- **CSV Backup & Import** - Export and import all dog/litter data as CSV files from the app documents directory
+- **Dynamic Theming** - Switch between Dark/Light modes and multiple accent colors
- **Offline-First** - All data stored locally using SQLite via Drift
## Screenshots
@@ -143,11 +144,13 @@ flutter build apk --release
## UI Screens
-1. **Dashboard** - Search bar, dog list, quick-add FAB
-2. **Dog Detail** - Identity card + interactive 3-gen pedigree canvas with PDF export/share
-3. **Litter Form** - 3-step wizard (parents -> dates -> puppy roster)
-4. **Settings** - Kennel profile, logo upload, CSV backup/import
-5. **About** - Developer info, links, in-app changelog
+1. **Dashboard** - Search bar, dog list, quick-add FAB, litter list link
+2. **Dog Detail** - Identity card, photo, interactive pedigree canvas with PDF export/share
+3. **Dog Edit** - Edit existing dog profiles with photo upload
+4. **Litter List** - Browse all registered litters with details
+5. **Litter Form** - 3-step wizard (parents -> dates -> puppy roster)
+6. **Settings** - Kennel profile, logo upload, CSV backup/import with dedup validation
+7. **About** - Developer info, links, in-app changelog
## Changelog
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 1c62dfe..291a349 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -13,7 +13,6 @@ linter:
- sized_box_for_whitespace
- prefer_is_empty
- prefer_is_not_empty
- - avoid_relative_lib_imports
- prefer_relative_imports
- always_declare_return_types
- annotate_overrides
diff --git a/android/app/src/main/res/drawable-hdpi/ic_launcher_foreground.png b/android/app/src/main/res/drawable-hdpi/ic_launcher_foreground.png
index b0673d3..15232b8 100644
Binary files a/android/app/src/main/res/drawable-hdpi/ic_launcher_foreground.png and b/android/app/src/main/res/drawable-hdpi/ic_launcher_foreground.png differ
diff --git a/android/app/src/main/res/drawable-mdpi/ic_launcher_foreground.png b/android/app/src/main/res/drawable-mdpi/ic_launcher_foreground.png
index 2cb5f65..4f17be1 100644
Binary files a/android/app/src/main/res/drawable-mdpi/ic_launcher_foreground.png and b/android/app/src/main/res/drawable-mdpi/ic_launcher_foreground.png differ
diff --git a/android/app/src/main/res/drawable-xhdpi/ic_launcher_foreground.png b/android/app/src/main/res/drawable-xhdpi/ic_launcher_foreground.png
index 0ea785a..55f3882 100644
Binary files a/android/app/src/main/res/drawable-xhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/drawable-xhdpi/ic_launcher_foreground.png differ
diff --git a/android/app/src/main/res/drawable-xxhdpi/ic_launcher_foreground.png b/android/app/src/main/res/drawable-xxhdpi/ic_launcher_foreground.png
index eae53e0..f9ecca2 100644
Binary files a/android/app/src/main/res/drawable-xxhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/drawable-xxhdpi/ic_launcher_foreground.png differ
diff --git a/android/app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png b/android/app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png
index 3537b9e..2b7a875 100644
Binary files a/android/app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png differ
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
index 6e8c343..6f45359 100644
Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
index bfe7cb1..357ea0f 100644
Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index 20a279e..32707a8 100644
Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 8f0dfc7..401ce4c 100644
Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index bd825f2..9f7aeca 100644
Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/appbarlogo.png b/appbarlogo.png
deleted file mode 100644
index 81176a5..0000000
Binary files a/appbarlogo.png and /dev/null differ
diff --git a/assets/images/ZooPed.png b/assets/images/ZooPed.png
index abf2f75..20bd6db 100644
Binary files a/assets/images/ZooPed.png and b/assets/images/ZooPed.png differ
diff --git a/assets/images/logo.png b/assets/images/logo.png
index 7f7f811..64cb3a7 100644
Binary files a/assets/images/logo.png and b/assets/images/logo.png differ
diff --git a/lib/core/database/app_database.dart b/lib/core/database/app_database.dart
index fb6a73b..e674ad0 100644
--- a/lib/core/database/app_database.dart
+++ b/lib/core/database/app_database.dart
@@ -10,7 +10,10 @@ class KennelProfile extends Table {
IntColumn get id => integer().withDefault(const Constant(1))();
TextColumn get kennelName => text().withLength(min: 1, max: 100)();
TextColumn get breederName => text().nullable()();
- TextColumn get contactInfo => text().nullable()();
+ TextColumn get contactInfo => text().nullable()(); // legacy
+ TextColumn get phone => text().nullable()();
+ TextColumn get whatsapp => text().nullable()();
+ TextColumn get email => text().nullable()();
TextColumn get localLogoPath => text().nullable()();
@override
@@ -27,7 +30,9 @@ class Dogs extends Table {
TextColumn get colorMarkings => text().nullable()();
// Self-referencing foreign keys for lineage
+ @ReferenceName('siredDogs')
IntColumn get sireId => integer().references(Dogs, #id).nullable()();
+ @ReferenceName('damDogs')
IntColumn get damId => integer().references(Dogs, #id).nullable()();
IntColumn get litterId => integer().nullable()(); // No foreign key to avoid circular reference
@@ -37,14 +42,17 @@ class Dogs extends Table {
TextColumn get registerType => text().nullable()(); // 'SP', 'SR', 'B'
TextColumn get dnaProfileNumber => text().nullable()();
+ TextColumn get photoPath => text().nullable()();
TextColumn get notes => text().nullable()();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
}
class Litters extends Table {
IntColumn get id => integer().autoIncrement()();
- IntColumn get sireId => integer().references(Dogs, #id)();
- IntColumn get damId => integer().references(Dogs, #id)();
+ @ReferenceName('siredLitters')
+ IntColumn get sireId => integer().references(Dogs, #id).nullable()();
+ @ReferenceName('damLitters')
+ IntColumn get damId => integer().references(Dogs, #id).nullable()();
DateTimeColumn get matingDate => dateTime().nullable()();
DateTimeColumn get whelpingDate => dateTime()();
IntColumn get puppiesBornAlive => integer().withDefault(const Constant(0))();
@@ -52,28 +60,110 @@ class Litters extends Table {
TextColumn get notes => text().nullable()();
}
-@DriftDatabase(tables: [KennelProfile, Dogs, Litters])
+class DogPhotos extends Table {
+ IntColumn get id => integer().autoIncrement()();
+ IntColumn get dogId => integer().references(Dogs, #id)();
+ TextColumn get photoPath => text()();
+ TextColumn get caption => text().nullable()();
+ DateTimeColumn get dateAdded => dateTime().withDefault(currentDateAndTime)();
+}
+
+class HealthRecords extends Table {
+ IntColumn get id => integer().autoIncrement()();
+ IntColumn get dogId => integer().references(Dogs, #id)();
+ TextColumn get recordType => text().withLength(min: 1, max: 50)(); // 'Vaccine', 'Deworming', 'Vet', 'Heat'
+ DateTimeColumn get date => dateTime()();
+ DateTimeColumn get nextDueDate => dateTime().nullable()();
+ TextColumn get notes => text().nullable()();
+ DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
+}
+
+class ShowRecords extends Table {
+ IntColumn get id => integer().autoIncrement()();
+ IntColumn get dogId => integer().references(Dogs, #id)();
+ TextColumn get eventName => text().withLength(min: 1, max: 100)();
+ DateTimeColumn get date => dateTime()();
+ TextColumn get judge => text().nullable()();
+ TextColumn get placement => text().nullable()();
+ TextColumn get titleAwarded => text().nullable()();
+ TextColumn get notes => text().nullable()();
+ DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
+}
+
+@DriftDatabase(
+ tables: [KennelProfile, Dogs, Litters, DogPhotos, HealthRecords, ShowRecords],
+ daos: [],
+)
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
@override
- int get schemaVersion => 1;
+ int get schemaVersion => 7;
@override
MigrationStrategy get migration {
return MigrationStrategy(
onCreate: (Migrator m) async {
await m.createAll();
- // Insert default kennel profile
await into(kennelProfile).insert(
KennelProfileCompanion.insert(
kennelName: 'My Kennel',
),
);
},
+ onUpgrade: (Migrator m, int from, int to) async {
+ if (from < 2) {
+ await m.addColumn(dogs, dogs.photoPath);
+ }
+ if (from < 3) {
+ await m.createTable(dogPhotos);
+ }
+ if (from < 4) {
+ await m.createTable(healthRecords);
+ }
+ if (from < 5) {
+ await m.createTable(showRecords);
+ }
+ if (from < 6) {
+ await m.addColumn(kennelProfile, kennelProfile.phone);
+ await m.addColumn(kennelProfile, kennelProfile.whatsapp);
+ await m.addColumn(kennelProfile, kennelProfile.email);
+ }
+ if (from < 7) {
+ await customStatement('PRAGMA foreign_keys = OFF');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_sire_id ON dogs(sire_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_dam_id ON dogs(dam_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_litter_id ON dogs(litter_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_sex ON dogs(sex)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_litters_sire_id ON litters(sire_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_litters_dam_id ON litters(dam_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dog_photos_dog_id ON dog_photos(dog_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_health_records_dog_id ON health_records(dog_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_show_records_dog_id ON show_records(dog_id)');
+ await customStatement('PRAGMA foreign_keys = ON');
+ }
+ },
+ beforeOpen: (details) async {
+ await customStatement('PRAGMA foreign_keys = ON');
+ if (details.wasCreated) {
+ await _createIndexes();
+ }
+ },
);
}
+ Future<void> _createIndexes() async {
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_sire_id ON dogs(sire_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_dam_id ON dogs(dam_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_litter_id ON dogs(litter_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dogs_sex ON dogs(sex)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_litters_sire_id ON litters(sire_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_litters_dam_id ON litters(dam_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_dog_photos_dog_id ON dog_photos(dog_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_health_records_dog_id ON health_records(dog_id)');
+ await customStatement('CREATE INDEX IF NOT EXISTS idx_show_records_dog_id ON show_records(dog_id)');
+ }
+
// Kennel Profile Operations
Future<KennelProfileData> getKennelProfile() async {
final profile = await select(kennelProfile).getSingleOrNull();
@@ -104,6 +194,11 @@ class AppDatabase extends _$AppDatabase {
return await (select(dogs)..where((d) => d.id.equals(id))).getSingle();
}
+ Future<List<Dog>> getDogsByIds(List<int> ids) async {
+ if (ids.isEmpty) return [];
+ return await (select(dogs)..where((d) => d.id.isIn(ids))).get();
+ }
+
Future<Dog?> getDogByIdOrNull(int id) async {
return await (select(dogs)..where((d) => d.id.equals(id))).getSingleOrNull();
}
@@ -122,9 +217,14 @@ class AppDatabase extends _$AppDatabase {
}
Future<void> deleteDog(int id) async {
- await (update(dogs)..where((d) => d.sireId.equals(id))).write(const DogsCompanion(sireId: Value(null)));
- await (update(dogs)..where((d) => d.damId.equals(id))).write(const DogsCompanion(damId: Value(null)));
- await (delete(dogs)..where((d) => d.id.equals(id))).go();
+ await transaction(() async {
+ await (delete(dogPhotos)..where((p) => p.dogId.equals(id))).go();
+ await (update(dogs)..where((d) => d.sireId.equals(id))).write(const DogsCompanion(sireId: Value(null)));
+ await (update(dogs)..where((d) => d.damId.equals(id))).write(const DogsCompanion(damId: Value(null)));
+ await (update(litters)..where((l) => l.sireId.equals(id))).write(const LittersCompanion(sireId: Value(null)));
+ await (update(litters)..where((l) => l.damId.equals(id))).write(const LittersCompanion(damId: Value(null)));
+ await (delete(dogs)..where((d) => d.id.equals(id))).go();
+ });
}
Future<List<Dog>> getDogsForDropdown(String sex) async {
@@ -164,6 +264,48 @@ class AppDatabase extends _$AppDatabase {
return dogMap.values.toList()..sort((a, b) => a.id.compareTo(b.id));
}
+ // Photo Gallery Operations
+ Future<int> addDogPhoto(DogPhotosCompanion photo) async {
+ return await into(dogPhotos).insert(photo);
+ }
+
+ Future<void> deleteDogPhoto(int id) async {
+ await (delete(dogPhotos)..where((p) => p.id.equals(id))).go();
+ }
+
+ Future<List<DogPhoto>> getPhotosForDog(int dogId) async {
+ return await (select(dogPhotos)..where((p) => p.dogId.equals(dogId))
+ ..orderBy([(p) => OrderingTerm.desc(p.dateAdded)])).get();
+ }
+
+ // Health Record Operations
+ Future<int> addHealthRecord(HealthRecordsCompanion record) async {
+ return await into(healthRecords).insert(record);
+ }
+
+ Future<void> deleteHealthRecord(int id) async {
+ await (delete(healthRecords)..where((r) => r.id.equals(id))).go();
+ }
+
+ Future<List<HealthRecord>> getHealthRecordsForDog(int dogId) async {
+ return await (select(healthRecords)..where((r) => r.dogId.equals(dogId))
+ ..orderBy([(r) => OrderingTerm.desc(r.date)])).get();
+ }
+
+ // Show Record Operations
+ Future<int> addShowRecord(ShowRecordsCompanion record) async {
+ return await into(showRecords).insert(record);
+ }
+
+ Future<void> deleteShowRecord(int id) async {
+ await (delete(showRecords)..where((r) => r.id.equals(id))).go();
+ }
+
+ Future<List<ShowRecord>> getShowRecordsForDog(int dogId) async {
+ return await (select(showRecords)..where((r) => r.dogId.equals(dogId))
+ ..orderBy([(r) => OrderingTerm.desc(r.date)])).get();
+ }
+
// Litter Operations
Future<int> createLitter(LittersCompanion litter) async {
return await into(litters).insert(litter);
@@ -178,14 +320,39 @@ class AppDatabase extends _$AppDatabase {
}
Future<void> deleteLitter(int id) async {
- await (update(dogs)..where((d) => d.litterId.equals(id))).write(const DogsCompanion(litterId: Value(null)));
- await (delete(litters)..where((l) => l.id.equals(id))).go();
+ await transaction(() async {
+ await (update(dogs)..where((d) => d.litterId.equals(id))).write(const DogsCompanion(litterId: Value(null)));
+ await (delete(litters)..where((l) => l.id.equals(id))).go();
+ });
+ }
+
+ Future<List<Litter>> getLittersForDog(int dogId) async {
+ return await (select(litters)..where((l) => l.sireId.equals(dogId) | l.damId.equals(dogId))).get();
+ }
+
+ Future<List<Dog>> getOffspringForDog(int dogId) async {
+ return await (select(dogs)..where((d) => d.sireId.equals(dogId) | d.damId.equals(dogId))).get();
}
Future<List<Dog>> getAllDogs() async {
return await select(dogs).get();
}
+ Future<List<Dog>> getFilteredDogs({String? sex, String? sortBy}) async {
+ var query = select(dogs);
+ if (sex != null && sex != 'All') {
+ query = query..where((d) => d.sex.equals(sex));
+ }
+ if (sortBy == 'Name (A-Z)') {
+ query = query..orderBy([(d) => OrderingTerm.asc(d.callName)]);
+ } else if (sortBy == 'Recent') {
+ query = query..orderBy([(d) => OrderingTerm.desc(d.id)]);
+ } else if (sortBy == 'Age (Youngest)') {
+ query = query..orderBy([(d) => OrderingTerm.desc(d.dateOfBirth)]);
+ }
+ return await query.get();
+ }
+
Future<List<Litter>> getAllLitters() async {
return await select(litters).get();
}
@@ -201,6 +368,17 @@ class AppDatabase extends _$AppDatabase {
batch.insertAll(litters, littersList);
});
}
+
+ Future<int> createLitterWithPuppies(LittersCompanion litter, List<DogsCompanion> puppies) async {
+ return await transaction(() async {
+ final litterId = await into(litters).insert(litter);
+ for (final puppy in puppies) {
+ final withLitterId = puppy.copyWith(litterId: Value(litterId));
+ await into(dogs).insert(withLitterId);
+ }
+ return litterId;
+ });
+ }
}
LazyDatabase _openConnection() {
diff --git a/lib/core/router/app_router.dart b/lib/core/router/app_router.dart
index 574c10e..fb7d290 100644
--- a/lib/core/router/app_router.dart
+++ b/lib/core/router/app_router.dart
@@ -3,9 +3,26 @@ import 'package:go_router/go_router.dart';
import '../../features/pedigree/presentation/screens/dashboard_screen.dart';
import '../../features/pedigree/presentation/screens/dog_detail_screen.dart';
import '../../features/pedigree/presentation/screens/add_dog_screen.dart';
+import '../../features/pedigree/presentation/screens/edit_dog_screen.dart';
import '../../features/pedigree/presentation/screens/litter_form_screen.dart';
+import '../../features/pedigree/presentation/screens/litter_list_screen.dart';
import '../../features/settings/presentation/screens/settings_screen.dart';
+import '../../features/settings/presentation/screens/kennel_profile_screen.dart';
+import '../../features/settings/presentation/screens/backup_migration_screen.dart';
import '../../features/settings/presentation/screens/about_screen.dart';
+import '../../features/settings/presentation/screens/appearance_screen.dart';
+import '../../features/pedigree/presentation/screens/add_health_record_screen.dart';
+import '../../features/pedigree/presentation/screens/matchmaker_screen.dart';
+import '../../features/pedigree/presentation/screens/add_show_record_screen.dart';
+
+int? _parseId(GoRouterState state, {String key = 'id'}) {
+ final idStr = state.pathParameters[key];
+ return int.tryParse(idStr ?? '');
+}
+
+Widget _invalidIdScreen() => const Scaffold(
+ body: Center(child: Text('Invalid dog ID')),
+);
class AppRouter {
static final GoRouter router = GoRouter(
@@ -20,34 +37,87 @@ class AppRouter {
GoRoute(
path: '/dog/new',
builder: (BuildContext context, GoRouterState state) {
- return const AddDogScreen();
+ final extra = state.extra as Map<String, dynamic>?;
+ return AddDogScreen(
+ childId: extra?['childId'] as int?,
+ isSire: extra?['isSire'] as bool?,
+ );
},
),
GoRoute(
path: '/dog/:id',
builder: (BuildContext context, GoRouterState state) {
- final idStr = state.pathParameters['id'];
- final id = int.tryParse(idStr ?? '');
- if (id == null) {
- return const Scaffold(
- body: Center(child: Text('Invalid dog ID')),
- );
- }
+ final id = _parseId(state);
+ if (id == null) return _invalidIdScreen();
return DogDetailScreen(dogId: id);
},
),
+ GoRoute(
+ path: '/dog/:id/edit',
+ builder: (BuildContext context, GoRouterState state) {
+ final id = _parseId(state);
+ if (id == null) return _invalidIdScreen();
+ return EditDogScreen(dogId: id);
+ },
+ ),
+ GoRoute(
+ path: '/dog/:id/health/new',
+ builder: (BuildContext context, GoRouterState state) {
+ final id = _parseId(state);
+ if (id == null) return _invalidIdScreen();
+ return AddHealthRecordScreen(dogId: id);
+ },
+ ),
+ GoRoute(
+ path: '/dog/:id/show/new',
+ builder: (BuildContext context, GoRouterState state) {
+ final id = _parseId(state);
+ if (id == null) return _invalidIdScreen();
+ return AddShowRecordScreen(dogId: id);
+ },
+ ),
GoRoute(
path: '/litter/new',
builder: (BuildContext context, GoRouterState state) {
return const LitterFormScreen();
},
),
+ GoRoute(
+ path: '/litters',
+ builder: (BuildContext context, GoRouterState state) {
+ return const LitterListScreen();
+ },
+ ),
GoRoute(
path: '/settings',
builder: (BuildContext context, GoRouterState state) {
return const SettingsScreen();
},
),
+ GoRoute(
+ path: '/settings/kennel',
+ builder: (BuildContext context, GoRouterState state) {
+ return const KennelProfileScreen();
+ },
+ ),
+ GoRoute(
+ path: '/settings/backup',
+ builder: (BuildContext context, GoRouterState state) {
+ return const BackupMigrationScreen();
+ },
+ ),
+ GoRoute(
+ path: '/settings/appearance',
+ builder: (BuildContext context, GoRouterState state) {
+ return const AppearanceScreen();
+ },
+ ),
+ GoRoute(
+ path: '/matchmaker',
+ builder: (BuildContext context, GoRouterState state) {
+ return const MatchmakerScreen();
+ },
+ ),
GoRoute(
path: '/about',
builder: (BuildContext context, GoRouterState state) {
diff --git a/lib/core/services/certificate_service.dart b/lib/core/services/certificate_service.dart
index 66d7b7f..c16278d 100644
--- a/lib/core/services/certificate_service.dart
+++ b/lib/core/services/certificate_service.dart
@@ -1,9 +1,8 @@
import 'dart:io';
+import 'package:intl/intl.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
-import 'package:path_provider/path_provider.dart';
-import 'package:path/path.dart' as p;
import 'package:share_plus/share_plus.dart';
import '../../features/pedigree/domain/entities/dog.dart';
import '../../features/settings/domain/entities/kennel_profile.dart';
@@ -13,230 +12,343 @@ class CertificateService {
required Dog dog,
required KennelProfile kennelProfile,
File? logoFile,
+ Map<int, pw.MemoryImage> preloadedImages = const {},
}) async {
final pdf = pw.Document();
final logoBytes = logoFile != null ? await logoFile.readAsBytes() : null;
final logoImage = logoBytes != null ? pw.MemoryImage(logoBytes) : null;
- pdf.addPage(
- pw.MultiPage(
- pageFormat: PdfPageFormat.a4,
- margin: const pw.EdgeInsets.all(40),
- build: (context) => [
- // Header
- if (logoImage != null)
- pw.Center(
- child: pw.Image(logoImage, height: 80),
- ),
- pw.SizedBox(height: 20),
- pw.Center(
- child: pw.Text(
- 'PEDIGREE CERTIFICATE',
- style: pw.TextStyle(
- fontSize: 24,
- fontWeight: pw.FontWeight.bold,
- color: PdfColor.fromHex('#3CB91A'),
- ),
- ),
- ),
- pw.SizedBox(height: 10),
- pw.Center(
- child: pw.Text(
- kennelProfile.kennelName,
- style: pw.TextStyle(
- fontSize: 16,
- color: PdfColor.fromHex('#3D3D3D'),
- ),
- ),
- ),
- if (kennelProfile.breederName != null)
- pw.Center(
- child: pw.Text(
- 'Breeder: ${kennelProfile.breederName}',
- style: const pw.TextStyle(
- fontSize: 12,
- color: PdfColors.grey700,
- ),
- ),
- ),
- pw.Divider(thickness: 2, color: PdfColor.fromHex('#3CB91A')),
- pw.SizedBox(height: 20),
-
- // Dog Information
- pw.Text(
- 'DOG INFORMATION',
- style: pw.TextStyle(
- fontSize: 14,
- fontWeight: pw.FontWeight.bold,
- color: PdfColor.fromHex('#3D3D3D'),
- ),
- ),
- pw.SizedBox(height: 10),
- _buildInfoRow('Registered Name', dog.registeredName),
- _buildInfoRow('Call Name', dog.callName),
- _buildInfoRow('Sex', dog.sex),
- if (dog.microchipNumber != null)
- _buildInfoRow('Microchip', dog.microchipNumber!),
- if (dog.dateOfBirth != null)
- _buildInfoRow('Date of Birth', dog.dateOfBirth.toString().split(' ')[0]),
- if (dog.colorMarkings != null)
- _buildInfoRow('Color / Markings', dog.colorMarkings!),
- if (dog.registerType != null)
- _buildInfoRow('Register Type', dog.registerType!),
- if (dog.appraisalScore != null)
- _buildInfoRow('Appraisal Score', dog.appraisalScore.toString()),
- if (dog.inbreedingCoefficient != null)
- _buildInfoRow('COI', dog.inbreedingCoefficient.toString()),
- if (dog.dnaProfileNumber != null)
- _buildInfoRow('DNA Profile', dog.dnaProfileNumber!),
- pw.SizedBox(height: 20),
-
- // Sire (Father)
- pw.Text(
- 'SIRE (FATHER)',
- style: pw.TextStyle(
- fontSize: 14,
- fontWeight: pw.FontWeight.bold,
- color: PdfColor.fromHex('#3D3D3D'),
- ),
- ),
- pw.SizedBox(height: 10),
- if (dog.sire != null) ...[
- _buildInfoRow('Name', dog.sire!.registeredName),
- _buildInfoRow('Call Name', dog.sire!.callName),
- if (dog.sire!.microchipNumber != null)
- _buildInfoRow('Microchip', dog.sire!.microchipNumber!),
- if (dog.sire!.sire != null)
- _buildInfoRow('Sire', dog.sire!.sire!.registeredName),
- if (dog.sire!.dam != null)
- _buildInfoRow('Dam', dog.sire!.dam!.registeredName),
- ] else
- pw.Text('Not registered', style: const pw.TextStyle(color: PdfColors.grey)),
- pw.SizedBox(height: 20),
+ final baseColor = PdfColor.fromHex('#2F5E36'); // Elegant dark green
+ final secondaryColor = PdfColor.fromHex('#4A4A4A'); // Dark grey
+ final lightGrey = PdfColor.fromHex('#E8E8E8');
- // Dam (Mother)
- pw.Text(
- 'DAM (MOTHER)',
- style: pw.TextStyle(
- fontSize: 14,
- fontWeight: pw.FontWeight.bold,
- color: PdfColor.fromHex('#3D3D3D'),
+ pdf.addPage(
+ pw.Page(
+ pageFormat: PdfPageFormat.a4.landscape,
+ margin: const pw.EdgeInsets.all(32),
+ build: (context) {
+ return pw.Container(
+ decoration: pw.BoxDecoration(
+ border: pw.Border.all(color: baseColor, width: 3),
),
- ),
- pw.SizedBox(height: 10),
- if (dog.dam != null) ...[
- _buildInfoRow('Name', dog.dam!.registeredName),
- _buildInfoRow('Call Name', dog.dam!.callName),
- if (dog.dam!.microchipNumber != null)
- _buildInfoRow('Microchip', dog.dam!.microchipNumber!),
- if (dog.dam!.sire != null)
- _buildInfoRow('Sire', dog.dam!.sire!.registeredName),
- if (dog.dam!.dam != null)
- _buildInfoRow('Dam', dog.dam!.dam!.registeredName),
- ] else
- pw.Text('Not registered', style: const pw.TextStyle(color: PdfColors.grey)),
- pw.SizedBox(height: 30),
+ padding: const pw.EdgeInsets.all(16),
+ child: pw.Row(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ // LEFT PANEL: Kennel & Dog Info (35% width)
+ pw.Expanded(
+ flex: 35,
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.center,
+ children: [
+ // Kennel Header
+ if (logoImage != null)
+ pw.Container(
+ height: 80,
+ child: pw.Image(logoImage),
+ ),
+ pw.SizedBox(height: 12),
+ pw.Text(
+ 'OFFICIAL PEDIGREE',
+ style: pw.TextStyle(
+ fontSize: 20,
+ fontWeight: pw.FontWeight.bold,
+ color: baseColor,
+ letterSpacing: 2,
+ ),
+ ),
+ pw.SizedBox(height: 8),
+ pw.Text(
+ kennelProfile.kennelName.toUpperCase(),
+ style: pw.TextStyle(
+ fontSize: 16,
+ fontWeight: pw.FontWeight.bold,
+ color: secondaryColor,
+ ),
+ ),
+ if (kennelProfile.breederName != null)
+ pw.Text(
+ 'Breeder: ${kennelProfile.breederName}',
+ style: const pw.TextStyle(fontSize: 10, color: PdfColors.black),
+ ),
+
+ // Contact Info
+ pw.SizedBox(height: 8),
+ pw.Container(
+ padding: const pw.EdgeInsets.all(8),
+ decoration: pw.BoxDecoration(
+ color: lightGrey,
+ borderRadius: const pw.BorderRadius.all(pw.Radius.circular(4)),
+ ),
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.center,
+ children: [
+ if (kennelProfile.phone != null)
+ pw.Text('Phone: ${kennelProfile.phone}', style: const pw.TextStyle(fontSize: 9)),
+ if (kennelProfile.whatsapp != null)
+ pw.Text('WhatsApp: ${kennelProfile.whatsapp}', style: const pw.TextStyle(fontSize: 9)),
+ if (kennelProfile.email != null)
+ pw.Text('Email: ${kennelProfile.email}', style: const pw.TextStyle(fontSize: 9)),
+ ],
+ ),
+ ),
+
+ pw.Divider(color: baseColor, thickness: 1.5),
+ pw.SizedBox(height: 8),
- // Grandparents Section (3 Gen)
- pw.Text(
- 'GRANDPARENTS',
- style: pw.TextStyle(
- fontSize: 14,
- fontWeight: pw.FontWeight.bold,
- color: PdfColor.fromHex('#3D3D3D'),
- ),
- ),
- pw.SizedBox(height: 10),
- _buildGrandparentRow('Sire\'s Sire', dog.sire?.sire),
- _buildGrandparentRow('Sire\'s Dam', dog.sire?.dam),
- _buildGrandparentRow('Dam\'s Sire', dog.dam?.sire),
- _buildGrandparentRow('Dam\'s Dam', dog.dam?.dam),
- pw.SizedBox(height: 30),
+ // Primary Dog Info
+ if (preloadedImages.containsKey(dog.id))
+ pw.Container(
+ width: 100,
+ height: 100,
+ decoration: pw.BoxDecoration(
+ shape: pw.BoxShape.circle,
+ image: pw.DecorationImage(
+ image: preloadedImages[dog.id]!,
+ fit: pw.BoxFit.cover,
+ ),
+ ),
+ ),
+ pw.SizedBox(height: 12),
+
+ pw.Text(
+ dog.registeredName,
+ textAlign: pw.TextAlign.center,
+ style: pw.TextStyle(
+ fontSize: 18,
+ fontWeight: pw.FontWeight.bold,
+ color: PdfColors.black,
+ ),
+ ),
+ pw.Text(
+ 'Call Name: "${dog.callName}"',
+ style: pw.TextStyle(fontSize: 12, fontStyle: pw.FontStyle.italic),
+ ),
+ pw.SizedBox(height: 12),
- // Footer
- pw.Divider(thickness: 1, color: PdfColors.grey300),
- pw.SizedBox(height: 10),
- pw.Row(
- mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
- children: [
- pw.Text(
- 'Generated: ${DateTime.now().toString().split('.')[0]}',
- style: const pw.TextStyle(
- fontSize: 10,
- color: PdfColors.grey600,
+ _buildDogDetailGrid(dog),
+ ],
+ ),
),
- ),
- pw.Text(
- 'ZooPed - Pedigree Management',
- style: const pw.TextStyle(
- fontSize: 10,
- color: PdfColors.grey600,
+
+ // Vertical Divider
+ pw.SizedBox(width: 16),
+ pw.Container(width: 1, color: lightGrey),
+ pw.SizedBox(width: 16),
+
+ // RIGHT PANEL: Pedigree Tree (65% width)
+ pw.Expanded(
+ flex: 65,
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ pw.Text(
+ '3-GENERATION PEDIGREE',
+ style: pw.TextStyle(
+ fontSize: 14,
+ fontWeight: pw.FontWeight.bold,
+ color: baseColor,
+ ),
+ ),
+ pw.SizedBox(height: 16),
+ pw.Expanded(
+ child: _buildTree(dog, preloadedImages, baseColor),
+ ),
+ ],
+ ),
),
- ),
- ],
- ),
- if (kennelProfile.contactInfo != null) ...[
- pw.SizedBox(height: 5),
- pw.Text(
- 'Contact: ${kennelProfile.contactInfo}',
- style: const pw.TextStyle(
- fontSize: 10,
- color: PdfColors.grey600,
- ),
+ ],
),
- ],
- ],
+ );
+ },
),
);
return pdf;
}
+ static pw.Widget _buildDogDetailGrid(Dog dog) {
+ return pw.Column(
+ children: [
+ _buildInfoRow('Sex', dog.sex),
+ if (dog.dateOfBirth != null)
+ _buildInfoRow('DOB', DateFormat('yyyy-MM-dd').format(dog.dateOfBirth!)),
+ if (dog.microchipNumber != null)
+ _buildInfoRow('Microchip', dog.microchipNumber!),
+ if (dog.colorMarkings != null)
+ _buildInfoRow('Color', dog.colorMarkings!),
+ if (dog.registerType != null)
+ _buildInfoRow('Registry', dog.registerType!),
+ if (dog.dnaProfileNumber != null)
+ _buildInfoRow('DNA Profile', dog.dnaProfileNumber!),
+ ],
+ );
+ }
+
static pw.Widget _buildInfoRow(String label, String value) {
return pw.Padding(
- padding: const pw.EdgeInsets.symmetric(vertical: 3),
+ padding: const pw.EdgeInsets.symmetric(vertical: 2),
child: pw.Row(
- crossAxisAlignment: pw.CrossAxisAlignment.start,
+ mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
- pw.SizedBox(
- width: 150,
+ pw.Text(label, style: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold)),
+ pw.SizedBox(width: 8),
+ pw.Expanded(
child: pw.Text(
- '$label:',
- style: pw.TextStyle(
- fontWeight: pw.FontWeight.bold,
- color: PdfColors.grey700,
- ),
+ value,
+ textAlign: pw.TextAlign.right,
+ style: const pw.TextStyle(fontSize: 10),
),
),
- pw.Expanded(
- child: pw.Text(value),
- ),
],
),
);
}
- static pw.Widget _buildGrandparentRow(String label, Dog? dog) {
- return pw.Padding(
- padding: const pw.EdgeInsets.symmetric(vertical: 3),
+ static pw.Widget _buildTree(Dog dog, Map<int, pw.MemoryImage> images, PdfColor color) {
+ // A standard 3-gen tree has 3 columns: Parents, Grandparents, Great-Grandparents.
+ // The data model goes: sire/dam (gen 1), their sire/dam (gen 2), their sire/dam (gen 3).
+ // In horizontal layout:
+ // Left col: Sire, Dam
+ // Middle col: Grandsire (Paternal), Granddam (Paternal), Grandsire (Maternal), Granddam (Maternal)
+ // Right col: Great-grandsires/dams
+
+ return pw.Row(
+ crossAxisAlignment: pw.CrossAxisAlignment.stretch,
+ children: [
+ // Parents (Gen 1)
+ pw.Expanded(
+ child: pw.Column(
+ mainAxisAlignment: pw.MainAxisAlignment.spaceAround,
+ children: [
+ _buildTreeNode(dog.sire, 'Sire', images, color),
+ _buildTreeNode(dog.dam, 'Dam', images, color),
+ ],
+ ),
+ ),
+ _buildConnectorLine(color),
+
+ // Grandparents (Gen 2)
+ pw.Expanded(
+ child: pw.Column(
+ mainAxisAlignment: pw.MainAxisAlignment.spaceAround,
+ children: [
+ _buildTreeNode(dog.sire?.sire, 'Grandsire', images, color),
+ _buildTreeNode(dog.sire?.dam, 'Granddam', images, color),
+ _buildTreeNode(dog.dam?.sire, 'Grandsire', images, color),
+ _buildTreeNode(dog.dam?.dam, 'Granddam', images, color),