mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Parse correctly conversation color
This commit is contained in:
parent
dacccf57b5
commit
a23b76b552
@ -17,6 +17,7 @@ import 'package:comunic/models/new_conversation_message.dart';
|
||||
import 'package:comunic/models/new_conversation_settings.dart';
|
||||
import 'package:comunic/models/unread_conversation.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:comunic/utils/dart_color.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Conversation helper
|
||||
@ -190,7 +191,7 @@ class ConversationsHelper {
|
||||
id: map["id"],
|
||||
lastActivity: map["last_activity"],
|
||||
name: map["name"],
|
||||
color: map["color"],
|
||||
color: map["color"] == null ? null : HexColor(map["color"]),
|
||||
logoURL: map["logo"],
|
||||
groupID: map["group_id"],
|
||||
members: map["members"]
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
|
||||
import 'package:comunic/models/conversation_member.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Conversation model
|
||||
@ -13,7 +14,7 @@ class Conversation extends SerializableElement<Conversation> {
|
||||
final int id;
|
||||
final int lastActivity;
|
||||
final String name;
|
||||
final String color;
|
||||
final Color color;
|
||||
final String logoURL;
|
||||
final int groupID;
|
||||
final List<ConversationMember> members;
|
||||
@ -61,7 +62,7 @@ class Conversation extends SerializableElement<Conversation> {
|
||||
Conversation.fromJson(Map<String, dynamic> map)
|
||||
: id = map["id"],
|
||||
name = map["name"],
|
||||
color = map["color"],
|
||||
color = map["color"] == null ? null : Color(map["color"]),
|
||||
logoURL = map["logoURL"],
|
||||
groupID = map["groupID"],
|
||||
lastActivity = map["lastActivity"],
|
||||
@ -78,7 +79,7 @@ class Conversation extends SerializableElement<Conversation> {
|
||||
return {
|
||||
"id": id,
|
||||
"name": name,
|
||||
"color": color,
|
||||
"color": color?.value,
|
||||
"logoURL": logoURL,
|
||||
"groupID": groupID,
|
||||
"lastActivity": lastActivity,
|
||||
|
@ -71,7 +71,7 @@ class ConversationTile extends StatelessWidget {
|
||||
conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
|
||||
color: conversation.sawLastMessage
|
||||
? (darkTheme() ? darkAccentColor : null)
|
||||
: Colors.blue,
|
||||
: conversation.color ?? Colors.blue,
|
||||
),
|
||||
|
||||
// Conversation information
|
||||
@ -79,8 +79,8 @@ class ConversationTile extends StatelessWidget {
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
_buildSubInformation(
|
||||
Icons.access_time, diffTimeFromNowToStr(conversation.lastActivity)),
|
||||
_buildSubInformation(Icons.access_time,
|
||||
diffTimeFromNowToStr(conversation.lastActivity)),
|
||||
_buildSubInformation(
|
||||
Icons.group,
|
||||
conversation.members.length == 1
|
||||
|
14
lib/utils/dart_color.dart
Normal file
14
lib/utils/dart_color.dart
Normal file
@ -0,0 +1,14 @@
|
||||
// https://stackoverflow.com/a/53905427
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HexColor extends Color {
|
||||
static int _getColorFromHex(String hexColor) {
|
||||
hexColor = hexColor.toUpperCase().replaceAll("#", "");
|
||||
if (hexColor.length == 6) {
|
||||
hexColor = "FF" + hexColor;
|
||||
}
|
||||
return int.parse(hexColor, radix: 16);
|
||||
}
|
||||
|
||||
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
|
||||
}
|
Loading…
Reference in New Issue
Block a user