2026-07-04 23:36:01 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2026-06-21 10:07:35 +02:00
|
|
|
import 'package:terepi_seged/enums/layer_import_source_type.dart';
|
2026-07-04 23:36:01 +02:00
|
|
|
import 'package:terepi_seged/services/layer_import_service.dart';
|
2026-06-21 10:07:35 +02:00
|
|
|
|
|
|
|
|
class ImportedLayerMeta {
|
|
|
|
|
final String id;
|
|
|
|
|
final String name;
|
|
|
|
|
final LayerImportSourceType sourceType;
|
|
|
|
|
final String localPath; // fájl elérési út
|
|
|
|
|
final String? storagePath; // Supabase Storage (megosztáskor)
|
|
|
|
|
final bool isVisible;
|
|
|
|
|
final int? projectId;
|
|
|
|
|
final DateTime importedAt;
|
|
|
|
|
final DateTime? syncedAt;
|
2026-07-04 23:36:01 +02:00
|
|
|
final String? colorHex;
|
|
|
|
|
final double? opacity;
|
|
|
|
|
final double? strokeWidth;
|
2026-06-21 10:07:35 +02:00
|
|
|
|
2026-07-04 23:36:01 +02:00
|
|
|
const ImportedLayerMeta(
|
|
|
|
|
{required this.id,
|
|
|
|
|
required this.name,
|
|
|
|
|
required this.sourceType,
|
|
|
|
|
required this.localPath,
|
|
|
|
|
this.storagePath,
|
|
|
|
|
this.isVisible = true,
|
|
|
|
|
this.projectId,
|
|
|
|
|
required this.importedAt,
|
|
|
|
|
this.syncedAt,
|
|
|
|
|
this.colorHex,
|
|
|
|
|
this.opacity,
|
|
|
|
|
this.strokeWidth});
|
2026-06-21 10:07:35 +02:00
|
|
|
|
|
|
|
|
bool get isSynced => storagePath != null;
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
'id': id,
|
|
|
|
|
'name': name,
|
|
|
|
|
'source_type': sourceType.name,
|
|
|
|
|
'local_path': localPath,
|
|
|
|
|
'storage_path': storagePath,
|
|
|
|
|
'is_visible': isVisible ? 1 : 0,
|
|
|
|
|
'project_id': projectId,
|
|
|
|
|
'imported_at': importedAt.toIso8601String(),
|
|
|
|
|
'synced_at': syncedAt?.toIso8601String(),
|
2026-07-04 23:36:01 +02:00
|
|
|
if (colorHex != null) 'color_hex': colorHex,
|
|
|
|
|
if (opacity != null) 'opacity': opacity,
|
|
|
|
|
if (strokeWidth != null) 'stroke_width': strokeWidth
|
2026-06-21 10:07:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
factory ImportedLayerMeta.fromMap(Map<String, dynamic> m) =>
|
|
|
|
|
ImportedLayerMeta(
|
2026-07-04 23:36:01 +02:00
|
|
|
id: m['id'] as String,
|
|
|
|
|
name: m['name'] as String,
|
|
|
|
|
sourceType:
|
|
|
|
|
LayerImportSourceType.values.byName(m['source_type'] as String),
|
|
|
|
|
localPath: m['local_path'] as String,
|
|
|
|
|
storagePath: m['storage_path'] as String?,
|
|
|
|
|
isVisible: (m['is_visible'] as int) == 1,
|
|
|
|
|
projectId: m['project_id'] as int?,
|
|
|
|
|
importedAt: DateTime.parse(m['imported_at'] as String),
|
|
|
|
|
syncedAt: m['synced_at'] != null
|
|
|
|
|
? DateTime.parse(m['synced_at'] as String)
|
|
|
|
|
: null,
|
|
|
|
|
colorHex: m['color_hex'] as String?,
|
|
|
|
|
opacity: (m['opacity'] as num?)?.toDouble(),
|
|
|
|
|
strokeWidth: (m['stroke_width'] as num?)?.toDouble());
|
2026-06-21 10:07:35 +02:00
|
|
|
|
|
|
|
|
ImportedLayerMeta copyWith({
|
|
|
|
|
bool? isVisible,
|
|
|
|
|
String? storagePath,
|
|
|
|
|
DateTime? syncedAt,
|
2026-07-04 23:36:01 +02:00
|
|
|
String? colorHex,
|
|
|
|
|
double? opacity,
|
|
|
|
|
double? strokeWidth,
|
2026-06-21 10:07:35 +02:00
|
|
|
}) =>
|
|
|
|
|
ImportedLayerMeta(
|
|
|
|
|
id: id,
|
|
|
|
|
name: name,
|
|
|
|
|
sourceType: sourceType,
|
|
|
|
|
localPath: localPath,
|
|
|
|
|
storagePath: storagePath ?? this.storagePath,
|
|
|
|
|
isVisible: isVisible ?? this.isVisible,
|
|
|
|
|
projectId: projectId,
|
|
|
|
|
importedAt: importedAt,
|
|
|
|
|
syncedAt: syncedAt ?? this.syncedAt,
|
2026-07-04 23:36:01 +02:00
|
|
|
colorHex: colorHex ?? this.colorHex,
|
|
|
|
|
opacity: opacity ?? this.opacity,
|
|
|
|
|
strokeWidth: strokeWidth ?? this.strokeWidth,
|
2026-06-21 10:07:35 +02:00
|
|
|
);
|
2026-07-04 23:36:01 +02:00
|
|
|
|
|
|
|
|
ImportedLayerStyle? getStyle() {
|
|
|
|
|
if (colorHex == null) return null;
|
|
|
|
|
final hex = colorHex!.replaceAll('#', '');
|
|
|
|
|
final color = Color(int.parse('FF$hex', radix: 16));
|
|
|
|
|
|
|
|
|
|
return ImportedLayerStyle(
|
|
|
|
|
color: color,
|
|
|
|
|
opacity: opacity ?? 0.35,
|
|
|
|
|
strokeWidth: strokeWidth ?? 2.5);
|
|
|
|
|
}
|
2026-06-21 10:07:35 +02:00
|
|
|
}
|