attachment lint

This commit is contained in:
Deven Joshi
2021-05-04 16:48:57 +05:30
parent eb57c6eb9f
commit f236d92840
7 changed files with 324 additions and 299 deletions
@@ -10,13 +10,7 @@ typedef FailedBuilder = Widget Function(BuildContext, String);
/// Widget to display attachment upload state /// Widget to display attachment upload state
class AttachmentUploadStateBuilder extends StatelessWidget { class AttachmentUploadStateBuilder extends StatelessWidget {
final Message message; /// Constructor for creating an [AttachmentUploadStateBuilder] widget
final Attachment attachment;
final FailedBuilder? failedBuilder;
final WidgetBuilder? successBuilder;
final InProgressBuilder? inProgressBuilder;
final WidgetBuilder? preparingBuilder;
const AttachmentUploadStateBuilder({ const AttachmentUploadStateBuilder({
Key? key, Key? key,
required this.message, required this.message,
@@ -27,32 +21,46 @@ class AttachmentUploadStateBuilder extends StatelessWidget {
this.preparingBuilder, this.preparingBuilder,
}) : super(key: key); }) : super(key: key);
/// Message which attachment is added to
final Message message;
/// Attachment in concern
final Attachment attachment;
/// Widget to display when failed
final FailedBuilder? failedBuilder;
/// Widget to display when succeeded
final WidgetBuilder? successBuilder;
/// Widget to display when in progress
final InProgressBuilder? inProgressBuilder;
/// Widget to display when in prep
final WidgetBuilder? preparingBuilder;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (message.status == MessageSendingStatus.sent) { if (message.status == MessageSendingStatus.sent) {
return Offstage(); return const Offstage();
} }
final messageId = message.id; final messageId = message.id;
final attachmentId = attachment.id; final attachmentId = attachment.id;
final inProgress = inProgressBuilder ?? final inProgress = inProgressBuilder ??
(context, int sent, int total) { (context, int sent, int total) => _InProgressState(
return _InProgressState( sent: sent,
sent: sent, total: total,
total: total, attachmentId: attachmentId,
attachmentId: attachmentId, );
);
};
final failed = failedBuilder ?? final failed = failedBuilder ??
(context, error) { (context, error) => _FailedState(
return _FailedState( error: error,
error: error, messageId: messageId,
messageId: messageId, attachmentId: attachmentId,
attachmentId: attachmentId, );
);
};
final success = successBuilder ?? (context) => _SuccessState(); final success = successBuilder ?? (context) => _SuccessState();
@@ -69,11 +77,6 @@ class AttachmentUploadStateBuilder extends StatelessWidget {
} }
class _IconButton extends StatelessWidget { class _IconButton extends StatelessWidget {
final Widget? icon;
final double iconSize;
final VoidCallback? onPressed;
final Color? fillColor;
const _IconButton({ const _IconButton({
Key? key, Key? key,
this.icon, this.icon,
@@ -82,36 +85,39 @@ class _IconButton extends StatelessWidget {
this.fillColor, this.fillColor,
}) : super(key: key); }) : super(key: key);
final Widget? icon;
final double iconSize;
final VoidCallback? onPressed;
final Color? fillColor;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => SizedBox(
return Container( height: iconSize,
height: iconSize, width: iconSize,
width: iconSize, child: RawMaterialButton(
child: RawMaterialButton( elevation: 0,
elevation: 0, highlightElevation: 0,
highlightElevation: 0, focusElevation: 0,
focusElevation: 0, hoverElevation: 0,
hoverElevation: 0, onPressed: onPressed,
onPressed: onPressed, fillColor:
fillColor: fillColor ?? StreamChatTheme.of(context).colorTheme.overlayDark,
fillColor ?? StreamChatTheme.of(context).colorTheme.overlayDark, shape: RoundedRectangleBorder(
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(16), ),
child: icon,
), ),
child: icon, );
),
);
}
} }
class _PreparingState extends StatelessWidget { class _PreparingState extends StatelessWidget {
final String attachmentId;
const _PreparingState({ const _PreparingState({
Key? key, Key? key,
required this.attachmentId, required this.attachmentId,
}) : super(key: key); }) : super(key: key);
final String attachmentId;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
@@ -141,10 +147,6 @@ class _PreparingState extends StatelessWidget {
} }
class _InProgressState extends StatelessWidget { class _InProgressState extends StatelessWidget {
final int sent;
final int total;
final String attachmentId;
const _InProgressState({ const _InProgressState({
Key? key, Key? key,
required this.sent, required this.sent,
@@ -152,6 +154,10 @@ class _InProgressState extends StatelessWidget {
required this.attachmentId, required this.attachmentId,
}) : super(key: key); }) : super(key: key);
final int sent;
final int total;
final String attachmentId;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
@@ -181,10 +187,6 @@ class _InProgressState extends StatelessWidget {
} }
class _FailedState extends StatelessWidget { class _FailedState extends StatelessWidget {
final String? error;
final String messageId;
final String attachmentId;
const _FailedState({ const _FailedState({
Key? key, Key? key,
this.error, this.error,
@@ -192,6 +194,10 @@ class _FailedState extends StatelessWidget {
required this.attachmentId, required this.attachmentId,
}) : super(key: key); }) : super(key: key);
final String? error;
final String messageId;
final String attachmentId;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
@@ -235,16 +241,14 @@ class _FailedState extends StatelessWidget {
class _SuccessState extends StatelessWidget { class _SuccessState extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => Align(
return Align( alignment: Alignment.topRight,
alignment: Alignment.topRight, child: CircleAvatar(
child: CircleAvatar( backgroundColor: StreamChatTheme.of(context).colorTheme.overlayDark,
backgroundColor: StreamChatTheme.of(context).colorTheme.overlayDark, maxRadius: 12,
maxRadius: 12, child: StreamSvgIcon.check(
child: StreamSvgIcon.check( color: StreamChatTheme.of(context).colorTheme.white,
color: StreamChatTheme.of(context).colorTheme.white, ),
), ),
), );
);
}
} }
@@ -1,13 +1,17 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
import '../stream_chat_theme.dart'; /// Enum for identifying type of attachment
enum AttachmentSource { enum AttachmentSource {
/// Attachment is attached
local, local,
/// Attachment is uploaded
network, network,
} }
/// Extension for identifying type of attachment
extension AttachmentSourceX on AttachmentSource { extension AttachmentSourceX on AttachmentSource {
/// The [when] method is the equivalent to pattern matching. /// The [when] method is the equivalent to pattern matching.
/// Its prototype depends on the AttachmentSource defined. /// Its prototype depends on the AttachmentSource defined.
@@ -25,18 +29,9 @@ extension AttachmentSourceX on AttachmentSource {
} }
} }
/// Abstract class for deriving attachment types
abstract class AttachmentWidget extends StatelessWidget { abstract class AttachmentWidget extends StatelessWidget {
final Size? size; /// Constructor for creating attachment widget
final AttachmentSource? _source;
final Message message;
final Attachment attachment;
AttachmentSource get source =>
_source ??
(attachment.file != null
? AttachmentSource.local
: AttachmentSource.network);
const AttachmentWidget({ const AttachmentWidget({
Key? key, Key? key,
required this.message, required this.message,
@@ -45,30 +40,48 @@ abstract class AttachmentWidget extends StatelessWidget {
AttachmentSource? source, AttachmentSource? source,
}) : _source = source, }) : _source = source,
super(key: key); super(key: key);
/// Size of attachments
final Size? size;
final AttachmentSource? _source;
/// Message which attachment is attached to
final Message message;
/// Attachment to display
final Attachment attachment;
/// Getter for source of attachment
AttachmentSource get source =>
_source ??
(attachment.file != null
? AttachmentSource.local
: AttachmentSource.network);
} }
/// Widget for building in case of error
class AttachmentError extends StatelessWidget { class AttachmentError extends StatelessWidget {
final Size? size; /// Constructor for creating AttachmentError
const AttachmentError({ const AttachmentError({
Key? key, Key? key,
this.size, this.size,
}) : super(key: key); }) : super(key: key);
final Size? size;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => Center(
return Center( child: Container(
child: Container( width: size?.width,
width: size?.width, height: size?.height,
height: size?.height, color:
color: StreamChatTheme.of(context).colorTheme.accentRed.withOpacity(.1), StreamChatTheme.of(context).colorTheme.accentRed.withOpacity(.1),
child: Center( child: Center(
child: Icon( child: Icon(
Icons.error_outline, Icons.error_outline,
color: StreamChatTheme.of(context).colorTheme.black, color: StreamChatTheme.of(context).colorTheme.black,
),
), ),
), ),
), );
);
}
} }
@@ -11,10 +11,7 @@ import '../upload_progress_indicator.dart';
import 'attachment_widget.dart'; import 'attachment_widget.dart';
class FileAttachment extends AttachmentWidget { class FileAttachment extends AttachmentWidget {
final Widget? title; /// Constructor for creating a widget when attachment is of type 'file'
final Widget? trailing;
final VoidCallback? onAttachmentTap;
const FileAttachment({ const FileAttachment({
Key? key, Key? key,
required Message message, required Message message,
@@ -30,8 +27,19 @@ class FileAttachment extends AttachmentWidget {
size: size, size: size,
); );
/// Title for attachment
final Widget? title;
/// Widget for displaying at the end of attachment (such as a download button)
final Widget? trailing;
/// Callback called when attachment widget is tapped
final VoidCallback? onAttachmentTap;
/// Check if attachment is a video
bool get isVideoAttachment => attachment.title?.mimeType?.type == 'video'; bool get isVideoAttachment => attachment.title?.mimeType?.type == 'video';
/// Check if attachment is an image
bool get isImageAttachment => attachment.title?.mimeType?.type == 'image'; bool get isImageAttachment => attachment.title?.mimeType?.type == 'image';
@override @override
@@ -56,10 +64,10 @@ class FileAttachment extends AttachmentWidget {
Container( Container(
height: 40, height: 40,
width: 33.33, width: 33.33,
margin: EdgeInsets.all(8), margin: const EdgeInsets.all(8),
child: _getFileTypeImage(context), child: _getFileTypeImage(context),
), ),
SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@@ -71,12 +79,12 @@ class FileAttachment extends AttachmentWidget {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
SizedBox(height: 3), const SizedBox(height: 3),
_buildSubtitle(context), _buildSubtitle(context),
], ],
), ),
), ),
SizedBox(width: 8), const SizedBox(width: 8),
_buildTrailing(context), _buildTrailing(context),
], ],
), ),
@@ -85,12 +93,10 @@ class FileAttachment extends AttachmentWidget {
); );
} }
ShapeBorder _getDefaultShape(BuildContext context) { ShapeBorder _getDefaultShape(BuildContext context) => RoundedRectangleBorder(
return RoundedRectangleBorder( side: const BorderSide(width: 0, color: Colors.transparent),
side: BorderSide(width: 0, color: Colors.transparent), borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(8), );
);
}
Widget _getFileTypeImage(BuildContext context) { Widget _getFileTypeImage(BuildContext context) {
if (isImageAttachment) { if (isImageAttachment) {
@@ -106,10 +112,8 @@ class FileAttachment extends AttachmentWidget {
return Image.memory( return Image.memory(
attachment.file!.bytes!, attachment.file!.bytes!,
fit: BoxFit.cover, fit: BoxFit.cover,
errorBuilder: (_, obj, trace) { errorBuilder: (_, obj, trace) =>
return getFileTypeImage( getFileTypeImage(attachment.extraData['other'] as String?),
attachment.extraData['other'] as String?);
},
); );
}, },
network: () { network: () {
@@ -124,10 +128,8 @@ class FileAttachment extends AttachmentWidget {
attachment.assetUrl ?? attachment.assetUrl ??
attachment.thumbUrl!, attachment.thumbUrl!,
fit: BoxFit.cover, fit: BoxFit.cover,
errorWidget: (_, obj, trace) { errorWidget: (_, obj, trace) =>
return getFileTypeImage( getFileTypeImage(attachment.extraData['other'] as String?),
attachment.extraData['other'] as String?);
},
placeholder: (_, __) { placeholder: (_, __) {
final image = Image.asset( final image = Image.asset(
'images/placeholder.png', 'images/placeholder.png',
@@ -156,27 +158,23 @@ class FileAttachment extends AttachmentWidget {
child: source.when( child: source.when(
local: () => VideoThumbnailImage( local: () => VideoThumbnailImage(
video: attachment.file!.path!, video: attachment.file!.path!,
placeholderBuilder: (_) { placeholderBuilder: (_) => const Center(
return Center( child: SizedBox(
child: Container( width: 20,
width: 20, height: 20,
height: 20, child: CircularProgressIndicator(),
child: const CircularProgressIndicator(), ),
), ),
);
},
), ),
network: () => VideoThumbnailImage( network: () => VideoThumbnailImage(
video: attachment.assetUrl!, video: attachment.assetUrl!,
placeholderBuilder: (_) { placeholderBuilder: (_) => const Center(
return Center( child: SizedBox(
child: Container( width: 20,
width: 20, height: 20,
height: 20, child: CircularProgressIndicator(),
child: const CircularProgressIndicator(), ),
), ),
);
},
), ),
), ),
); );
@@ -189,22 +187,22 @@ class FileAttachment extends AttachmentWidget {
double iconSize = 24.0, double iconSize = 24.0,
VoidCallback? onPressed, VoidCallback? onPressed,
Color? fillColor, Color? fillColor,
}) { }) =>
return Container( SizedBox(
height: iconSize, height: iconSize,
width: iconSize, width: iconSize,
child: RawMaterialButton( child: RawMaterialButton(
elevation: 0, elevation: 0,
highlightElevation: 0, highlightElevation: 0,
focusElevation: 0, focusElevation: 0,
hoverElevation: 0, hoverElevation: 0,
onPressed: onPressed, onPressed: onPressed,
fillColor: fillColor, fillColor: fillColor,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), shape:
child: icon, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
), child: icon,
); ),
} );
Widget _buildTrailing(BuildContext context) { Widget _buildTrailing(BuildContext context) {
final theme = StreamChatTheme.of(context); final theme = StreamChatTheme.of(context);
@@ -281,26 +279,22 @@ class FileAttachment extends AttachmentWidget {
color: theme.colorTheme.grey, color: theme.colorTheme.grey,
); );
return attachment.uploadState.when( return attachment.uploadState.when(
preparing: () { preparing: () => UploadProgressIndicator(
return UploadProgressIndicator( uploaded: 0,
uploaded: 0, total: double.maxFinite.toInt(),
total: double.maxFinite.toInt(), showBackground: false,
showBackground: false, padding: EdgeInsets.zero,
padding: EdgeInsets.zero, textStyle: textStyle,
textStyle: textStyle, progressIndicatorColor: theme.colorTheme.accentBlue,
progressIndicatorColor: theme.colorTheme.accentBlue, ),
); inProgress: (sent, total) => UploadProgressIndicator(
}, uploaded: sent,
inProgress: (sent, total) { total: total,
return UploadProgressIndicator( showBackground: false,
uploaded: sent, padding: EdgeInsets.zero,
total: total, textStyle: textStyle,
showBackground: false, progressIndicatorColor: theme.colorTheme.accentBlue,
padding: EdgeInsets.zero, ),
textStyle: textStyle,
progressIndicatorColor: theme.colorTheme.accentBlue,
);
},
success: () => Text(fileSize(size), style: textStyle), success: () => Text(fileSize(size), style: textStyle),
failed: (_) => Text('UPLOAD ERROR', style: textStyle), failed: (_) => Text('UPLOAD ERROR', style: textStyle),
) ?? ) ??
@@ -1,18 +1,13 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
import '../full_screen_media.dart'; /// Widget for showing a GIF attachment
import '../stream_chat_theme.dart';
import '../stream_svg_icon.dart';
import 'attachment_widget.dart';
class GiphyAttachment extends AttachmentWidget { class GiphyAttachment extends AttachmentWidget {
final ShowMessageCallback? onShowMessage; /// Constructor for creating a [GiphyAttachment] widget
final ValueChanged<ReturnActionType>? onReturnAction;
final VoidCallback? onAttachmentTap;
const GiphyAttachment({ const GiphyAttachment({
Key? key, Key? key,
required Message message, required Message message,
@@ -28,12 +23,21 @@ class GiphyAttachment extends AttachmentWidget {
size: size, size: size,
); );
/// Callback when show message is tapped
final ShowMessageCallback? onShowMessage;
/// Callback when attachment is returned to from other screens
final ValueChanged<ReturnActionType>? onReturnAction;
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final imageUrl = final imageUrl =
attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl; attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl;
if (imageUrl == null) { if (imageUrl == null) {
return AttachmentError(); return const AttachmentError();
} }
if (attachment.actions.isNotEmpty) { if (attachment.actions.isNotEmpty) {
return _buildSendingAttachment(context, imageUrl); return _buildSendingAttachment(context, imageUrl);
@@ -50,10 +54,9 @@ class GiphyAttachment extends AttachmentWidget {
color: StreamChatTheme.of(context).colorTheme.white, color: StreamChatTheme.of(context).colorTheme.white,
elevation: 2, elevation: 2,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topRight: Radius.circular(16), topRight: Radius.circular(16),
bottomRight: Radius.circular(0),
topLeft: Radius.circular(16), topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16), bottomLeft: Radius.circular(16),
), ),
@@ -67,12 +70,12 @@ class GiphyAttachment extends AttachmentWidget {
child: Row( child: Row(
children: [ children: [
StreamSvgIcon.giphyIcon(), StreamSvgIcon.giphyIcon(),
SizedBox(width: 8), const SizedBox(width: 8),
Text( const Text(
'Giphy', 'Giphy',
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
), ),
SizedBox(width: 8), const SizedBox(width: 8),
if (attachment.title != null) if (attachment.title != null)
Flexible( Flexible(
child: Text( child: Text(
@@ -97,19 +100,16 @@ class GiphyAttachment extends AttachmentWidget {
child: CachedNetworkImage( child: CachedNetworkImage(
height: size?.height, height: size?.height,
width: size?.width, width: size?.width,
placeholder: (_, __) { placeholder: (_, __) => SizedBox(
return Container( width: size?.width,
width: size?.width, height: size?.height,
height: size?.height, child: const Center(
child: Center( child: CircularProgressIndicator(),
child: CircularProgressIndicator(), ),
), ),
);
},
imageUrl: imageUrl, imageUrl: imageUrl,
errorWidget: (context, url, error) { errorWidget: (context, url, error) =>
return AttachmentError(size: size); AttachmentError(size: size),
},
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
@@ -125,7 +125,7 @@ class GiphyAttachment extends AttachmentWidget {
Row( Row(
children: [ children: [
Expanded( Expanded(
child: Container( child: SizedBox(
height: 50, height: 50,
child: TextButton( child: TextButton(
onPressed: () { onPressed: () {
@@ -157,7 +157,7 @@ class GiphyAttachment extends AttachmentWidget {
height: 50, height: 50,
), ),
Expanded( Expanded(
child: Container( child: SizedBox(
height: 50, height: 50,
child: TextButton( child: TextButton(
onPressed: () { onPressed: () {
@@ -190,7 +190,7 @@ class GiphyAttachment extends AttachmentWidget {
height: 50, height: 50,
), ),
Expanded( Expanded(
child: Container( child: SizedBox(
height: 50, height: 50,
child: TextButton( child: TextButton(
onPressed: () { onPressed: () {
@@ -215,7 +215,7 @@ class GiphyAttachment extends AttachmentWidget {
], ],
), ),
), ),
SizedBox(height: 4), const SizedBox(height: 4),
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Padding( child: Padding(
@@ -230,7 +230,7 @@ class GiphyAttachment extends AttachmentWidget {
.withOpacity(0.5), .withOpacity(0.5),
size: 16, size: 16,
), ),
SizedBox( const SizedBox(
width: 8, width: 8,
), ),
Text( Text(
@@ -273,88 +273,86 @@ class GiphyAttachment extends AttachmentWidget {
if (res != null) onReturnAction?.call(res); if (res != null) onReturnAction?.call(res);
} }
Widget _buildSentAttachment(BuildContext context, String imageUrl) { Widget _buildSentAttachment(BuildContext context, String imageUrl) =>
return Container( SizedBox(
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: () async {
final res = final res =
await Navigator.push(context, MaterialPageRoute(builder: (_) { await Navigator.push(context, MaterialPageRoute(builder: (_) {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
return StreamChannel( return StreamChannel(
channel: channel, channel: channel,
child: FullScreenMedia( child: FullScreenMedia(
mediaAttachments: [attachment], mediaAttachments: [attachment],
userName: message.user?.name, userName: message.user?.name,
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
), ),
); );
})); }));
if (res != null) onReturnAction!(res); if (res != null) onReturnAction!(res);
}, },
child: Stack( child: Stack(
children: [ children: [
CachedNetworkImage( CachedNetworkImage(
height: size?.height, height: size?.height,
width: size?.width, width: size?.width,
placeholder: (_, __) { placeholder: (_, __) {
final image = Image.asset( final image = Image.asset(
'images/placeholder.png', 'images/placeholder.png',
fit: BoxFit.cover, fit: BoxFit.cover,
package: 'stream_chat_flutter', package: 'stream_chat_flutter',
); );
final colorTheme = StreamChatTheme.of(context).colorTheme; final colorTheme = StreamChatTheme.of(context).colorTheme;
return Shimmer.fromColors( return Shimmer.fromColors(
baseColor: colorTheme.greyGainsboro, baseColor: colorTheme.greyGainsboro,
highlightColor: colorTheme.whiteSmoke, highlightColor: colorTheme.whiteSmoke,
child: image, child: image,
); );
}, },
imageUrl: imageUrl, imageUrl: imageUrl,
errorWidget: (context, url, error) { errorWidget: (context, url, error) =>
return AttachmentError(size: size); AttachmentError(size: size),
}, fit: BoxFit.cover,
fit: BoxFit.cover, ),
), Positioned(
Positioned( bottom: 8,
bottom: 8, left: 8,
left: 8, child: Material(
child: Material( color: StreamChatTheme.of(context)
color: StreamChatTheme.of(context) .colorTheme
.colorTheme .black
.black .withOpacity(.5),
.withOpacity(.5), shape: RoundedRectangleBorder(
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
), ),
child: Row( child: Padding(
children: [ padding: const EdgeInsets.symmetric(
StreamSvgIcon.lightning( horizontal: 8,
color: StreamChatTheme.of(context).colorTheme.white, vertical: 4,
size: 16, ),
), child: Row(
Text( children: [
'GIPHY', StreamSvgIcon.lightning(
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.white, color: StreamChatTheme.of(context).colorTheme.white,
fontWeight: FontWeight.bold, size: 16,
fontSize: 11,
), ),
), Text(
], 'GIPHY',
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.white,
fontWeight: FontWeight.bold,
fontSize: 11,
),
),
],
),
), ),
), ),
), ),
), ],
], ),
), ),
), );
);
}
} }
@@ -1,21 +1,15 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_title.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_upload_state_builder.dart'; import 'package:stream_chat_flutter/src/attachment/attachment_upload_state_builder.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
import '../full_screen_media.dart'; /// Widget for showing an image attachment
import '../stream_chat_theme.dart';
import 'attachment_title.dart';
import 'attachment_widget.dart';
class ImageAttachment extends AttachmentWidget { class ImageAttachment extends AttachmentWidget {
final MessageTheme messageTheme; /// Constructor for creating a [ImageAttachment] widget
final bool showTitle;
final ShowMessageCallback? onShowMessage;
final ValueChanged<ReturnActionType>? onReturnAction;
final VoidCallback? onAttachmentTap;
const ImageAttachment({ const ImageAttachment({
Key? key, Key? key,
required Message message, required Message message,
@@ -33,6 +27,21 @@ class ImageAttachment extends AttachmentWidget {
size: size, size: size,
); );
/// [MessageTheme] for showing image title
final MessageTheme messageTheme;
/// Flag for showing title
final bool showTitle;
/// Callback when show message is tapped
final ShowMessageCallback? onShowMessage;
/// Callback when attachment is returned to from other screens
final ValueChanged<ReturnActionType>? onReturnAction;
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
@override @override
Widget build(BuildContext context) => source.when( Widget build(BuildContext context) => source.when(
local: () { local: () {
@@ -1,18 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_title.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart';
import 'package:stream_chat_flutter/src/full_screen_media.dart'; import 'package:stream_chat_flutter/src/full_screen_media.dart';
import 'package:stream_chat_flutter/src/video_thumbnail_image.dart'; import 'package:stream_chat_flutter/src/video_thumbnail_image.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'attachment_title.dart'; /// Widget for showing a video attachment
import 'attachment_upload_state_builder.dart';
import 'attachment_widget.dart';
class VideoAttachment extends AttachmentWidget { class VideoAttachment extends AttachmentWidget {
final MessageTheme messageTheme; /// Constructor for creating a [VideoAttachment] widget
final ShowMessageCallback? onShowMessage;
final ValueChanged<ReturnActionType>? onReturnAction;
final VoidCallback? onAttachmentTap;
const VideoAttachment({ const VideoAttachment({
Key? key, Key? key,
required Message message, required Message message,
@@ -29,6 +24,18 @@ class VideoAttachment extends AttachmentWidget {
size: size, size: size,
); );
/// [MessageTheme] for showing title
final MessageTheme messageTheme;
/// Callback when show message is tapped
final ShowMessageCallback? onShowMessage;
/// Callback when attachment is returned to from other screens
final ValueChanged<ReturnActionType>? onReturnAction;
/// Callback when attachment is tapped
final VoidCallback? onAttachmentTap;
@override @override
Widget build(BuildContext context) => source.when( Widget build(BuildContext context) => source.when(
local: () { local: () {
@@ -100,7 +100,7 @@ class ChannelInfo extends StatelessWidget {
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
), ),
SizedBox(width: 10), const SizedBox(width: 10),
Text( Text(
'Searching for Network', 'Searching for Network',
style: textStyle, style: textStyle,