Skip to content

Commit

Permalink
TW-180: Change padding displayName and avt in ForwardItem
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Jun 22, 2023
1 parent 7bc43d7 commit 3a4d735
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 108 deletions.
3 changes: 1 addition & 2 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ class ChatView extends StatelessWidget {
onTapDown: controller.setReadMarker,
behavior: HitTestBehavior.opaque,
child: StreamBuilder(
stream: controller.room!.onUpdate.stream
.rateLimit(const Duration(seconds: 1)),
stream: controller.room!.onUpdate.stream.rateLimit(const Duration(seconds: 1)),
builder: (context, snapshot) => FutureBuilder<bool>(
future: controller.getTimeline(),
builder: (BuildContext context, snapshot) {
Expand Down
106 changes: 36 additions & 70 deletions lib/pages/chat/events/image_bubble.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_blurhash/flutter_blurhash.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:fluffychat/widgets/mxc_image.dart';

class ImageBubble extends StatefulWidget {
class ImageBubble extends StatelessWidget {
final Event event;
final bool tapToView;
final BoxFit fit;
Expand Down Expand Up @@ -34,27 +31,19 @@ class ImageBubble extends StatefulWidget {
Key? key,
}) : super(key: key);

@override
State<ImageBubble> createState() => _ImageBubbleState();
}

class _ImageBubbleState extends State<ImageBubble> {

Uint8List? _imageDataCached;

Widget _buildPlaceholder(BuildContext context) {
if (widget.event.messageType == MessageTypes.Sticker) {
if (event.messageType == MessageTypes.Sticker) {
return const Center(
child: CircularProgressIndicator.adaptive(),
);
}
final String blurHashString =
widget.event.infoMap['xyz.amorgan.blurhash'] is String
? widget.event.infoMap['xyz.amorgan.blurhash']
: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
final ratio = widget.event.infoMap['w'] is int && widget.event.infoMap['h'] is int
? widget.event.infoMap['w'] / widget.event.infoMap['h']
: 1.0;
event.infoMap['xyz.amorgan.blurhash'] is String
? event.infoMap['xyz.amorgan.blurhash']
: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
final ratio = event.infoMap['w'] is int && event.infoMap['h'] is int
? event.infoMap['w'] / event.infoMap['h']
: 1.0;
var width = 32;
var height = 32;
if (ratio > 1.0) {
Expand All @@ -63,67 +52,44 @@ class _ImageBubbleState extends State<ImageBubble> {
width = (height * ratio).round();
}
return SizedBox(
width: widget.width,
height: widget.height,
width: this.width,
height: this.height,
child: BlurHash(
hash: blurHashString,
decodingWidth: width,
decodingHeight: height,
imageFit: widget.fit,
imageFit: fit,
),
);
}

void _onTap(BuildContext context) async {
if (widget.onTapPreview != null) {
widget.onTapPreview!();
} else {
widget.onTapSelectMode!();
return;
}
if (!widget.tapToView) return;
await showGeneralDialog(
context: context,
useRootNavigator: false,
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (_, animationOne, animationTwo) =>
ImageViewer(widget.event, imageData: _imageDataCached)
);
}

@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => _onTap(context),
child: Hero(
tag: widget.event.eventId,
child: AnimatedSwitcher(
duration: const Duration(seconds: 1),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20)
),
constraints: widget.maxSize
? BoxConstraints(
maxWidth: widget.width,
maxHeight: widget.height,
)
: null,
child: MxcImage(
rounded: true,
event: widget.event,
width: widget.width,
height: widget.height,
fit: widget.fit,
animated: widget.animated,
isThumbnail: widget.thumbnailOnly,
placeholder: _buildPlaceholder,
callbackImage: (image) {
_imageDataCached = image;
},
),
return Hero(
tag: event.eventId,
child: AnimatedSwitcher(
duration: const Duration(seconds: 1),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20)
),
constraints: maxSize
? BoxConstraints(
maxWidth: width,
maxHeight: height,
)
: null,
child: MxcImage(
rounded: true,
event: event,
width: width,
height: height,
fit: fit,
animated: animated,
isThumbnail: thumbnailOnly,
placeholder: _buildPlaceholder,
onTapPreview: onTapPreview,
onTapSelectMode: onTapSelectMode,
),
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class MessageContent extends StatelessWidget {
final void Function(Event)? onInfoTab;
final Widget endOfBubbleWidget;
final Color backgroundColor;
final Function()? onTapPreview;
final Function()? onTapSelectMode;
final Function()? onTapPreview;
final Function()? onTapSelectMode;

const MessageContent(
this.event, {
Expand Down Expand Up @@ -133,6 +133,7 @@ class MessageContent extends StatelessWidget {
return SendingImageWidget(
sendingImageData: sendingImageData,
event: event,
onTapPreview: onTapPreview,
);
}
return ImageBubble(
Expand Down
40 changes: 30 additions & 10 deletions lib/pages/chat/events/sending_image_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:typed_data';

import 'package:fluffychat/pages/chat/events/message_content_style.dart';
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:flutter/material.dart';
import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart';
import 'package:matrix/matrix.dart' hide Visibility;
Expand All @@ -9,14 +10,30 @@ class SendingImageWidget extends StatelessWidget {
SendingImageWidget({
super.key,
required this.sendingImageData,
required this.event,
required this.event, this.onTapPreview,
});

final Uint8List sendingImageData;

final Event event;

final ValueNotifier<double> sendingFileProgressNotifier = ValueNotifier(0);
final void Function()? onTapPreview;

final ValueNotifier<double> sendingFileProgressNotifier = ValueNotifier(0);

void _onTap(BuildContext context) async {
if (onTapPreview != null) {
await showGeneralDialog(
context: context,
useRootNavigator: false,
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (_, animationOne, animationTwo) =>
ImageViewer(event, imageData: sendingImageData)
);
}
}

@override
Widget build(BuildContext context) {
Expand All @@ -42,14 +59,17 @@ class SendingImageWidget extends StatelessWidget {
],
);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Image.memory(
sendingImageData,
width: MessageContentStyle.imageBubbleWidth,
height: MessageContentStyle.imageBubbleHeight,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
child: InkWell(
onTap: () => _onTap(context),
child: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Image.memory(
sendingImageData,
width: MessageContentStyle.imageBubbleWidth,
height: MessageContentStyle.imageBubbleHeight,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/forward/forward_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ForwardItem extends StatelessWidget {
],
),
),
const SizedBox(width: 4),
const SizedBox(width: 8),
Flexible(
child: Text(
displayName,
Expand Down
1 change: 1 addition & 0 deletions lib/pages/image_viewer/image_viewer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ImageViewerView extends StatelessWidget {
fit: BoxFit.contain,
isThumbnail: false,
animated: false,
imageData: imageData,
),
),
),
Expand Down
60 changes: 37 additions & 23 deletions lib/widgets/mxc_image.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:typed_data';

import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:flutter/material.dart';

import 'package:http/http.dart' as http;
import 'package:matrix/matrix.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
Expand All @@ -24,7 +22,8 @@ class MxcImage extends StatefulWidget {
final Widget Function(BuildContext context)? placeholder;
final String? cacheKey;
final bool rounded;
final Function(Uint8List uint8list)? callbackImage;
final void Function()? onTapPreview;
final void Function()? onTapSelectMode;
final Uint8List? imageData;

const MxcImage({
Expand All @@ -42,7 +41,8 @@ class MxcImage extends StatefulWidget {
this.thumbnailMethod = ThumbnailMethod.scale,
this.cacheKey,
this.rounded = false,
this.callbackImage,
this.onTapPreview,
this.onTapSelectMode,
this.imageData,
Key? key,
}) : super(key: key);
Expand All @@ -60,9 +60,6 @@ class _MxcImageState extends State<MxcImage> {
Uint8List? get _imageData {
final cacheKey = widget.cacheKey;
final image = cacheKey == null ? _imageDataNoCache : _imageDataCache[cacheKey];
if (image != null ) {
widget.callbackImage?.call(image);
}
return image;
}

Expand Down Expand Up @@ -144,11 +141,7 @@ class _MxcImageState extends State<MxcImage> {
}

void _tryLoad(_) async {
if (widget.imageData != null) {
_imageData = widget.imageData;
isLoadDone = true;
return;
}
_imageData = widget.imageData;
if (_imageData != null) {
setState(() {
isLoadDone = true;
Expand All @@ -167,6 +160,24 @@ class _MxcImageState extends State<MxcImage> {
}
}

void _onTap(BuildContext context) async {
if (widget.onTapPreview != null) {
widget.onTapPreview!();
await showGeneralDialog(
context: context,
useRootNavigator: false,
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (_, animationOne, animationTwo) =>
ImageViewer(widget.event!, imageData: _imageData)
);
} else {
widget.onTapSelectMode!();
return;
}
}

@override
void initState() {
super.initState();
Expand All @@ -181,16 +192,19 @@ class _MxcImageState extends State<MxcImage> {

@override
Widget build(BuildContext context) {
return widget.animated
? AnimatedCrossFade(
duration: widget.animationDuration,
crossFadeState: isLoadDone ? CrossFadeState.showSecond : CrossFadeState.showFirst,
firstChild: SizedBox(
width: widget.width,
height: widget.height,
),
secondChild:_buildImageWidget())
: _buildImageWidget();
return InkWell(
onTap: () => _onTap(context),
child: widget.animated
? AnimatedCrossFade(
duration: widget.animationDuration,
crossFadeState: isLoadDone ? CrossFadeState.showSecond : CrossFadeState.showFirst,
firstChild: SizedBox(
width: widget.width,
height: widget.height,
),
secondChild:_buildImageWidget())
: _buildImageWidget(),
);
}

Widget _buildImageWidget() {
Expand Down

0 comments on commit 3a4d735

Please sign in to comment.