lint changes

This commit is contained in:
Deven Joshi
2021-05-05 16:19:54 +05:30
parent a55af6befb
commit ef837a4d7d
2 changed files with 170 additions and 173 deletions
@@ -1,17 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
/// List tile for [ChannelBottomSheet]
class OptionListTile extends StatelessWidget { class OptionListTile extends StatelessWidget {
final String? title; /// Constructor for creating [OptionListTile]
final Widget? leading;
final Widget? trailing;
final VoidCallback? onTap;
final Color? titleColor;
final Color? tileColor;
final Color? separatorColor;
final TextStyle? titleTextStyle;
const OptionListTile({ const OptionListTile({
Key? key,
this.title, this.title,
this.leading, this.leading,
this.trailing, this.trailing,
@@ -20,11 +14,34 @@ class OptionListTile extends StatelessWidget {
this.tileColor, this.tileColor,
this.separatorColor, this.separatorColor,
this.titleTextStyle, this.titleTextStyle,
}); }) : super(key: key);
/// Title for tile
final String? title;
/// Leading widget (start)
final Widget? leading;
/// Trailing widget (end)
final Widget? trailing;
/// Callback when tile is tapped
final VoidCallback? onTap;
/// Title color
final Color? titleColor;
/// Background tile color
final Color? tileColor;
/// Separator color
final Color? separatorColor;
/// [TextStyle] to apply to [title]
final TextStyle? titleTextStyle;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => Column(
return Column(
children: [ children: [
Container( Container(
color: separatorColor ?? color: separatorColor ??
@@ -33,7 +50,7 @@ class OptionListTile extends StatelessWidget {
), ),
Material( Material(
color: tileColor ?? StreamChatTheme.of(context).colorTheme.white, color: tileColor ?? StreamChatTheme.of(context).colorTheme.white,
child: Container( child: SizedBox(
height: 63, height: 63,
child: InkWell( child: InkWell(
onTap: onTap, onTap: onTap,
@@ -41,7 +58,7 @@ class OptionListTile extends StatelessWidget {
children: [ children: [
if (leading != null) Center(child: leading), if (leading != null) Center(child: leading),
if (leading == null) if (leading == null)
SizedBox( const SizedBox(
width: 16, width: 16,
), ),
Expanded( Expanded(
@@ -77,4 +94,3 @@ class OptionListTile extends StatelessWidget {
], ],
); );
} }
}
@@ -4,29 +4,25 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter/src/extension.dart';
import 'attachment/attachment.dart'; /// Widget builder for quoted message attachment thumnail
import 'extension.dart';
import 'message_text.dart';
import 'stream_chat_theme.dart';
import 'user_avatar.dart';
import 'utils.dart';
typedef QuotedMessageAttachmentThumbnailBuilder = Widget Function( typedef QuotedMessageAttachmentThumbnailBuilder = Widget Function(
BuildContext, BuildContext,
Attachment, Attachment,
); );
class _VideoAttachmentThumbnail extends StatefulWidget { class _VideoAttachmentThumbnail extends StatefulWidget {
final Size size;
final Attachment attachment;
const _VideoAttachmentThumbnail({ const _VideoAttachmentThumbnail({
Key? key, Key? key,
required this.attachment, required this.attachment,
this.size = const Size(32, 32), this.size = const Size(32, 32),
}) : super(key: key); }) : super(key: key);
final Size size;
final Attachment attachment;
@override @override
_VideoAttachmentThumbnailState createState() => _VideoAttachmentThumbnailState createState() =>
_VideoAttachmentThumbnailState(); _VideoAttachmentThumbnailState();
@@ -51,18 +47,30 @@ class _VideoAttachmentThumbnailState extends State<_VideoAttachmentThumbnail> {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => SizedBox(
return Container(
height: widget.size.height, height: widget.size.height,
width: widget.size.width, width: widget.size.width,
child: _controller.value.isInitialized child: _controller.value.isInitialized
? VideoPlayer(_controller) ? VideoPlayer(_controller)
: CircularProgressIndicator()); : const CircularProgressIndicator(),
} );
} }
/// ///
class QuotedMessageWidget extends StatelessWidget { class QuotedMessageWidget extends StatelessWidget {
///
const QuotedMessageWidget({
Key? key,
required this.message,
required this.messageTheme,
this.reverse = false,
this.showBorder = false,
this.textLimit = 170,
this.attachmentThumbnailBuilders,
this.padding = const EdgeInsets.all(8),
this.onTap,
}) : super(key: key);
/// The message /// The message
final Message message; final Message message;
@@ -82,23 +90,12 @@ class QuotedMessageWidget extends StatelessWidget {
final Map<String, QuotedMessageAttachmentThumbnailBuilder>? final Map<String, QuotedMessageAttachmentThumbnailBuilder>?
attachmentThumbnailBuilders; attachmentThumbnailBuilders;
/// Padding around the widget
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
/// Callback for tap on widget
final GestureTapCallback? onTap; final GestureTapCallback? onTap;
///
const QuotedMessageWidget({
Key? key,
required this.message,
required this.messageTheme,
this.reverse = false,
this.showBorder = false,
this.textLimit = 170,
this.attachmentThumbnailBuilders,
this.padding = const EdgeInsets.all(8),
this.onTap,
}) : super(key: key);
bool get _hasAttachments => message.attachments.isNotEmpty == true; bool get _hasAttachments => message.attachments.isNotEmpty == true;
bool get _containsScrapeUrl => bool get _containsScrapeUrl =>
@@ -107,8 +104,7 @@ class QuotedMessageWidget extends StatelessWidget {
bool get _containsText => message.text?.isNotEmpty == true; bool get _containsText => message.text?.isNotEmpty == true;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => Padding(
return Padding(
padding: padding, padding: padding,
child: InkWell( child: InkWell(
onTap: onTap, onTap: onTap,
@@ -117,13 +113,12 @@ class QuotedMessageWidget extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Flexible(child: _buildMessage(context)), Flexible(child: _buildMessage(context)),
SizedBox(width: 8), const SizedBox(width: 8),
if (message.user != null) _buildUserAvatar(), if (message.user != null) _buildUserAvatar(),
], ],
), ),
), ),
); );
}
Widget _buildMessage(BuildContext context) { Widget _buildMessage(BuildContext context) {
final isOnlyEmoji = message.text!.isOnlyEmoji; final isOnlyEmoji = message.text!.isOnlyEmoji;
@@ -165,7 +160,7 @@ class QuotedMessageWidget extends StatelessWidget {
color: StreamChatTheme.of(context).colorTheme.greyGainsboro, color: StreamChatTheme.of(context).colorTheme.greyGainsboro,
) )
: null, : null,
borderRadius: BorderRadius.only( borderRadius: const BorderRadius.only(
topRight: Radius.circular(12), topRight: Radius.circular(12),
topLeft: Radius.circular(12), topLeft: Radius.circular(12),
bottomLeft: Radius.circular(12), bottomLeft: Radius.circular(12),
@@ -183,7 +178,7 @@ class QuotedMessageWidget extends StatelessWidget {
} }
Widget _buildUrlAttachment(Attachment attachment) { Widget _buildUrlAttachment(Attachment attachment) {
final size = Size(32, 32); const size = Size(32, 32);
if (attachment.thumbUrl != null) { if (attachment.thumbUrl != null) {
return Container( return Container(
height: size.height, height: size.height,
@@ -198,7 +193,7 @@ class QuotedMessageWidget extends StatelessWidget {
), ),
); );
} }
return AttachmentError(size: size); return const AttachmentError(size: size);
} }
Widget _parseAttachments(BuildContext context) { Widget _parseAttachments(BuildContext context) {
@@ -217,7 +212,7 @@ class QuotedMessageWidget extends StatelessWidget {
} }
attachmentBuilder = _defaultAttachmentBuilder[attachment.type]; attachmentBuilder = _defaultAttachmentBuilder[attachment.type];
if (attachmentBuilder == null) { if (attachmentBuilder == null) {
child = Offstage(); child = const Offstage();
} else { } else {
child = attachmentBuilder(context, attachment); child = attachmentBuilder(context, attachment);
} }
@@ -235,77 +230,63 @@ class QuotedMessageWidget extends StatelessWidget {
); );
} }
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 _buildUserAvatar() { Widget _buildUserAvatar() => Transform(
return Transform(
transform: Matrix4.rotationY(reverse ? pi : 0), transform: Matrix4.rotationY(reverse ? pi : 0),
alignment: Alignment.center, alignment: Alignment.center,
child: UserAvatar( child: UserAvatar(
user: message.user!, user: message.user!,
constraints: BoxConstraints.tightFor( constraints: const BoxConstraints.tightFor(
height: 24, height: 24,
width: 24, width: 24,
), ),
showOnlineStatus: false, showOnlineStatus: false,
), ),
); );
}
Map<String, QuotedMessageAttachmentThumbnailBuilder> Map<String, QuotedMessageAttachmentThumbnailBuilder>
get _defaultAttachmentBuilder { get _defaultAttachmentBuilder => {
return { 'image': (_, attachment) => ImageAttachment(
'image': (_, attachment) {
return ImageAttachment(
attachment: attachment, attachment: attachment,
message: message, message: message,
messageTheme: messageTheme, messageTheme: messageTheme,
size: Size(32, 32), size: const Size(32, 32),
); ),
}, 'video': (_, attachment) => _VideoAttachmentThumbnail(
'video': (_, attachment) {
return _VideoAttachmentThumbnail(
key: ValueKey(attachment.assetUrl), key: ValueKey(attachment.assetUrl),
attachment: attachment, attachment: attachment,
); ),
},
'giphy': (_, attachment) { 'giphy': (_, attachment) {
final size = Size(32, 32); const size = Size(32, 32);
return CachedNetworkImage( return 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: Center( child: const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
); ),
},
imageUrl: attachment.thumbUrl ?? imageUrl: attachment.thumbUrl ??
attachment.imageUrl ?? attachment.imageUrl ??
attachment.assetUrl!, attachment.assetUrl!,
errorWidget: (context, url, error) { errorWidget: (context, url, error) =>
return AttachmentError(size: size); const AttachmentError(size: size),
},
fit: BoxFit.cover, fit: BoxFit.cover,
); );
}, },
'file': (_, attachment) { 'file': (_, attachment) => SizedBox(
return Container(
height: 32, height: 32,
width: 32, width: 32,
child: getFileTypeImage(attachment.extraData['mime_type'] as String?), child: getFileTypeImage(
); attachment.extraData['mime_type'] as String?),
}, ),
}; };
}
Color? _getBackgroundColor(BuildContext context) { Color? _getBackgroundColor(BuildContext context) {
if (_containsScrapeUrl) { if (_containsScrapeUrl) {