Add image viewer

This commit is contained in:
Christian Pauly 2020-01-03 09:09:14 +01:00
parent bc7c6f00f4
commit d8027be729
2 changed files with 78 additions and 17 deletions

View file

@ -19,11 +19,50 @@ class ChatListItem extends StatelessWidget {
color: activeChat ? Color(0xFFE8E8E8) : Colors.white, color: activeChat ? Color(0xFFE8E8E8) : Colors.white,
child: ListTile( child: ListTile(
leading: Avatar(room.avatar), leading: Avatar(room.avatar),
title: Text( title: Row(
room.displayname, children: <Widget>[
maxLines: 1, Expanded(
child: Text(
room.displayname,
maxLines: 1,
),
),
Text(ChatTime(room.timeCreated).toEventTimeString()),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(child: MessageContent(room.lastEvent, textOnly: true)),
SizedBox(width: 8),
room.pushRuleState == PushRuleState.notify
? Container()
: Icon(
Icons.notifications_off,
color: Colors.grey,
size: 20,
),
room.notificationCount > 0
? Container(
width: 20,
height: 20,
margin: EdgeInsets.only(top: 3),
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: Color(0xFF5625BA),
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Text(
room.notificationCount.toString(),
style: TextStyle(color: Colors.white),
),
),
)
: Text(" "),
],
), ),
subtitle: MessageContent(room.lastEvent, textOnly: true),
onTap: () { onTap: () {
if (activeChat) { if (activeChat) {
Navigator.pushReplacement( Navigator.pushReplacement(
@ -38,7 +77,7 @@ class ChatListItem extends StatelessWidget {
} }
}, },
onLongPress: () {}, onLongPress: () {},
trailing: Container( /*trailing: Container(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
@ -65,7 +104,7 @@ class ChatListItem extends StatelessWidget {
: Text(" "), : Text(" "),
], ],
), ),
), ),*/
), ),
); );
} }

View file

@ -1,4 +1,9 @@
import 'dart:math';
import 'package:bubble/bubble.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -14,19 +19,36 @@ class MessageContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final int maxLines = textOnly ? 1 : null; final int maxLines = textOnly ? 1 : null;
if (textOnly) {
return Text(
event.getBody(),
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
maxLines: maxLines,
);
}
switch (event.type) { switch (event.type) {
case EventTypes.Audio:
case EventTypes.Image: case EventTypes.Image:
final int size = 400;
final String src = MxContent(event.content["url"]).getThumbnail(
Matrix.of(context).client,
width: size * MediaQuery.of(context).devicePixelRatio,
height: size * MediaQuery.of(context).devicePixelRatio,
method: ThumbnailMethod.scale,
);
return Bubble(
padding: BubbleEdges.all(0),
radius: Radius.circular(50),
elevation: 0,
child: InkWell(
onTap: () => launch(
MxContent(event.content["url"])
.getDownloadLink(Matrix.of(context).client),
),
child: kIsWeb
? Image.network(
src,
width: size.toDouble(),
)
: CachedNetworkImage(
imageUrl: src,
width: size.toDouble(),
),
),
);
case EventTypes.Audio:
case EventTypes.File: case EventTypes.File:
case EventTypes.Video: case EventTypes.Video:
return Container( return Container(