Use different default icon for public chats

parent e5169d74
// Copyright (C) 2019 wilko
//
// This file is part of Pattle.
//
// Pattle is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pattle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:mdi/mdi.dart';
import 'package:pattle/src/ui/resources/theme.dart';
import 'package:pattle/src/ui/util/matrix_image.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:pattle/src/ui/util/user.dart';
import 'package:transparent_image/transparent_image.dart';
class ChatAvatar extends StatelessWidget {
final Room room;
const ChatAvatar({Key key, this.room}) : super(key: key);
@override
Widget build(BuildContext context) {
final avatarUrl = avatarUrlOf(room);
if (avatarUrl != null) {
return Hero(
tag: room.id,
child: Container(
width: 48,
height: 48,
child: ClipOval(
child: FadeInImage(
fit: BoxFit.cover,
placeholder: MemoryImage(kTransparentImage),
image: MatrixImage(avatarUrl, width: 64, height: 64),
),
),
),
);
} else {
return CircleAvatar(
foregroundColor: Colors.white,
backgroundColor: room.isDirect
? colorOf(context, room.directUser)
: LightColors.red[500],
radius: 24,
child: _icon(),
);
}
}
Icon _icon() {
if (room.isDirect) {
return Icon(Icons.person);
} else if (room.aliases != null && room.aliases.isNotEmpty) {
return Icon(Mdi.bullhorn);
} else {
return Icon(Icons.group);
}
}
}
......@@ -18,13 +18,9 @@
import 'package:flutter/material.dart';
import 'package:pattle/src/app.dart';
import 'package:pattle/src/ui/main/overview/models/chat_overview.dart';
import 'package:pattle/src/ui/main/overview/widgets/chat_avatar.dart';
import 'package:pattle/src/ui/main/widgets/chat_name.dart';
import 'package:pattle/src/ui/resources/theme.dart';
import 'package:pattle/src/ui/util/date_format.dart';
import 'package:pattle/src/ui/util/matrix_image.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:pattle/src/ui/util/user.dart';
import 'package:transparent_image/transparent_image.dart';
import 'subtitle.dart';
......@@ -85,35 +81,6 @@ class ChatOverviewListState extends State<ChatOverviewList> {
Widget _buildChatOverview(ChatOverview chat) {
final time = formatAsListItem(context, chat.latestEvent?.time);
// Avatar
final avatarUrl = avatarUrlOf(chat.room);
var avatar;
if (avatarUrl != null) {
avatar = Hero(
tag: chat.room.id,
child: Container(
width: 48,
height: 48,
child: ClipOval(
child: FadeInImage(
fit: BoxFit.cover,
placeholder: MemoryImage(kTransparentImage),
image: MatrixImage(avatarUrl, width: 64, height: 64),
),
),
),
);
} else {
avatar = CircleAvatar(
foregroundColor: Colors.white,
backgroundColor: chat.room.isDirect
? colorOf(context, chat.room.directUser)
: LightColors.red[500],
radius: 24,
child: Icon(chat.room.isDirect ? Icons.person : Icons.group),
);
}
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
......@@ -137,7 +104,7 @@ class ChatOverviewListState extends State<ChatOverviewList> {
onTap: () {
Navigator.pushNamed(context, Routes.chats, arguments: chat.room);
},
leading: avatar,
leading: ChatAvatar(room: chat.room),
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
subtitle: Subtitle.forChat(chat),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment