1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-09 22:19:45 +00:00
app-mirror-github/lib/models/label.dart

48 lines
1.4 KiB
Dart
Raw Normal View History

2021-06-04 09:34:25 +00:00
import 'dart:ui';
import 'package:vikunja_app/models/user.dart';
2022-07-23 23:08:59 +00:00
import 'package:vikunja_app/theme/constants.dart';
2021-06-04 09:34:25 +00:00
class Label {
final int id;
2022-09-03 15:43:16 +00:00
final String title, description;
final DateTime created, updated;
2022-09-03 15:43:16 +00:00
final User createdBy;
final Color? color;
2021-06-04 09:34:25 +00:00
2022-09-03 15:43:16 +00:00
late final Color textColor = color != null && color!.computeLuminance() <= 0.5 ? vLabelLight : vLabelDark;
Label({
this.id = -1,
required this.title,
this.description = '',
this.color,
DateTime? created,
DateTime? updated,
required this.createdBy,
}) : this.created = created ?? DateTime.now(),
this.updated = updated ?? DateTime.now();
2021-06-04 09:34:25 +00:00
Label.fromJson(Map<String, dynamic> json)
: id = json['id'],
title = json['title'],
description = json['description'],
color = json['hex_color'] == ''
2022-09-03 15:43:16 +00:00
? null
2021-06-04 09:34:25 +00:00
: new Color(int.parse(json['hex_color'], radix: 16) + 0xFF000000),
2021-06-08 05:50:05 +00:00
updated = DateTime.parse(json['updated']),
created = DateTime.parse(json['created']),
2021-06-04 09:34:25 +00:00
createdBy = User.fromJson(json['created_by']);
toJSON() => {
2022-09-03 15:43:16 +00:00
'id': id != -1 ? id : null,
2021-06-04 09:34:25 +00:00
'title': title,
'description': description,
'hex_color':
2022-09-03 15:43:16 +00:00
color?.value.toRadixString(16).padLeft(8, '0').substring(2),
'created_by': createdBy.toJSON(),
'updated': updated.toUtc().toIso8601String(),
'created': created.toUtc().toIso8601String(),
2021-06-04 09:34:25 +00:00
};
}