creek

The AI Image Editor of 2030

lib/data/models/file_model.dart (1611B)


 1import 'dart:convert';
 2
 3class FileMetadataInfo {
 4  final double width;
 5  final double height;
 6  final String? previewPath;
 7
 8  FileMetadataInfo({this.width = 0, this.height = 0, this.previewPath});
 9
10  String get dimensions => '${width.toInt()} x ${height.toInt()} px';
11}
12
13class FileModel {
14  final String id;
15  final int projectId;
16  final String filePath;
17  final String name;
18  final String? description;
19  final List<String> tags;
20  final DateTime lastUpdated;
21  final DateTime createdAt;
22
23  FileModel({
24    required this.id,
25    required this.projectId,
26    required this.filePath,
27    required this.name,
28    this.description,
29    this.tags = const [],
30    required this.lastUpdated,
31    required this.createdAt,
32  });
33
34  Map<String, dynamic> toMap() {
35    return {
36      'id': id,
37      'project_id': projectId,
38      'file_path': filePath,
39      'name': name,
40      'description': description,
41      'tags': jsonEncode(tags),
42      'last_updated': lastUpdated.toIso8601String(),
43      'created_at': createdAt.toIso8601String(),
44    };
45  }
46
47  factory FileModel.fromMap(Map<String, dynamic> map) {
48    return FileModel(
49      id: map['id'],
50      projectId: map['project_id'],
51      filePath: map['file_path'],
52      name: map['name'] ?? 'Untitled',
53      description: map['description'],
54      tags:
55          map['tags'] != null ? List<String>.from(jsonDecode(map['tags'])) : [],
56      lastUpdated:
57          map['last_updated'] != null
58              ? DateTime.parse(map['last_updated'])
59              : DateTime.parse(map['created_at']),
60      createdAt: DateTime.parse(map['created_at']),
61    );
62  }
63}