1
0
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:
Pierre HUBERT 2021-03-10 18:04:29 +01:00
parent dacccf57b5
commit a23b76b552
4 changed files with 23 additions and 7 deletions

View File

@ -17,6 +17,7 @@ import 'package:comunic/models/new_conversation_message.dart';
import 'package:comunic/models/new_conversation_settings.dart'; import 'package:comunic/models/new_conversation_settings.dart';
import 'package:comunic/models/unread_conversation.dart'; import 'package:comunic/models/unread_conversation.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/dart_color.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
/// Conversation helper /// Conversation helper
@ -190,7 +191,7 @@ class ConversationsHelper {
id: map["id"], id: map["id"],
lastActivity: map["last_activity"], lastActivity: map["last_activity"],
name: map["name"], name: map["name"],
color: map["color"], color: map["color"] == null ? null : HexColor(map["color"]),
logoURL: map["logo"], logoURL: map["logo"],
groupID: map["group_id"], groupID: map["group_id"],
members: map["members"] members: map["members"]

View File

@ -1,6 +1,7 @@
import 'package:comunic/helpers/serialization/base_serialization_helper.dart'; import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
import 'package:comunic/models/conversation_member.dart'; import 'package:comunic/models/conversation_member.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
/// Conversation model /// Conversation model
@ -13,7 +14,7 @@ class Conversation extends SerializableElement<Conversation> {
final int id; final int id;
final int lastActivity; final int lastActivity;
final String name; final String name;
final String color; final Color color;
final String logoURL; final String logoURL;
final int groupID; final int groupID;
final List<ConversationMember> members; final List<ConversationMember> members;
@ -61,7 +62,7 @@ class Conversation extends SerializableElement<Conversation> {
Conversation.fromJson(Map<String, dynamic> map) Conversation.fromJson(Map<String, dynamic> map)
: id = map["id"], : id = map["id"],
name = map["name"], name = map["name"],
color = map["color"], color = map["color"] == null ? null : Color(map["color"]),
logoURL = map["logoURL"], logoURL = map["logoURL"],
groupID = map["groupID"], groupID = map["groupID"],
lastActivity = map["lastActivity"], lastActivity = map["lastActivity"],
@ -78,7 +79,7 @@ class Conversation extends SerializableElement<Conversation> {
return { return {
"id": id, "id": id,
"name": name, "name": name,
"color": color, "color": color?.value,
"logoURL": logoURL, "logoURL": logoURL,
"groupID": groupID, "groupID": groupID,
"lastActivity": lastActivity, "lastActivity": lastActivity,

View File

@ -71,7 +71,7 @@ class ConversationTile extends StatelessWidget {
conversation.sawLastMessage ? Icons.check_circle : Icons.lens, conversation.sawLastMessage ? Icons.check_circle : Icons.lens,
color: conversation.sawLastMessage color: conversation.sawLastMessage
? (darkTheme() ? darkAccentColor : null) ? (darkTheme() ? darkAccentColor : null)
: Colors.blue, : conversation.color ?? Colors.blue,
), ),
// Conversation information // Conversation information
@ -79,8 +79,8 @@ class ConversationTile extends StatelessWidget {
subtitle: Column( subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
_buildSubInformation( _buildSubInformation(Icons.access_time,
Icons.access_time, diffTimeFromNowToStr(conversation.lastActivity)), diffTimeFromNowToStr(conversation.lastActivity)),
_buildSubInformation( _buildSubInformation(
Icons.group, Icons.group,
conversation.members.length == 1 conversation.members.length == 1

14
lib/utils/dart_color.dart Normal file
View 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));
}