• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 30854254088

03 Aug 2026 09:21PM UTC coverage: 40.895% (-15.0%) from 55.93%
30854254088

Pull #1260

github

web-flow
Merge d93794de5 into e3affdd4f
Pull Request #1260: WIP: health sync

9980 of 24404 relevant lines covered (40.89%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.0
/lib/features/gallery/models/image.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (c) 2020 - 2026 wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'package:drift/drift.dart' as drift;
20
import 'package:json_annotation/json_annotation.dart';
21
import 'package:wger/core/json.dart';
22
import 'package:wger/database/powersync/database.dart';
23

24
part 'image.g.dart';
25

26
/// A single picture in the user's gallery.
27
///
28
/// [imagePath] holds the relative storage path (Django `ImageField`'s column
29
/// value, e.g. `gallery/1/abc.jpg`); resolve it via `mediaUrlBuilderProvider`
30
/// or render with `WgerImage(mediaPath: ...)`. JSON support is kept so the
31
/// REST POST response (which still handles uploads) hydrates cleanly.
32
@JsonSerializable()
33
class GalleryImage {
34
  // Mirrors the backend description max_length (server gallery/models/image.py).
35
  static const MAX_LENGTH_DESCRIPTION = 1000;
36

37
  @JsonKey(required: true)
38
  int? id;
39

40
  @JsonKey(required: true, fromJson: utcIso8601ToLocalDate, toJson: dateToUtcIso8601)
41
  late DateTime date;
42

43
  @JsonKey(name: 'image')
44
  String? imagePath;
45

46
  @JsonKey(defaultValue: '')
47
  late String description;
48

49
  GalleryImage({
4✔
50
    this.id,
51
    DateTime? date,
52
    this.imagePath,
53
    String? description,
54
  }) {
55
    this.date = date ?? DateTime.now();
4✔
56
    this.description = description ?? '';
4✔
57
  }
58

59
  /// Convenience for the form's "new image" path: an empty entry to be
60
  /// filled in by the user before upload.
61
  GalleryImage.empty() {
×
62
    date = DateTime.now();
×
63
    description = '';
×
64
  }
65

66
  // Boilerplate
67
  factory GalleryImage.fromJson(Map<String, dynamic> json) => _$GalleryImageFromJson(json);
×
68

69
  Map<String, dynamic> toJson() => _$GalleryImageToJson(this);
×
70

71
  /// Drift companion used for local UPDATE writes routed through PowerSync.
72
  ///
73
  /// Throws if [id] is null, creation goes through REST (file upload), so
74
  /// rows without a server-assigned id should never be written locally.
75
  /// The `image` column is intentionally omitted: file-changing edits also
76
  /// go through REST and metadata-only edits leave the path untouched.
77
  GalleryImageTableCompanion toCompanion() {
×
78
    final imageId = id;
×
79
    if (imageId == null) {
80
      throw StateError('Cannot persist gallery image without id (creation goes via REST)');
×
81
    }
82
    return GalleryImageTableCompanion(
×
83
      id: drift.Value(imageId),
×
84
      date: drift.Value(DateTime.utc(date.year, date.month, date.day)),
×
85
      description: drift.Value(description),
×
86
    );
87
  }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc