Skip to content

Commit

Permalink
WIP refactor attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilaair committed Oct 17, 2021
1 parent f0521c6 commit 983b6b4
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 445 deletions.
26 changes: 26 additions & 0 deletions lib/widgets/chat/attachment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:papercups_flutter/models/classes.dart';
import 'package:papercups_flutter/utils/utils.dart';

class Attachment extends StatelessWidget {
const Attachment({required this.userSent, required this.props, Key? key})
: super(key: key);

final bool userSent;
final Props props;

@override
Widget build(BuildContext context) {
return Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
color: userSent
? brighten(props.primaryColor!, 20)
: Theme.of(context).brightness == Brightness.light
? brighten(Theme.of(context).disabledColor, 80)
: Color(0xff282828),
),
);
}
}
2 changes: 1 addition & 1 deletion lib/widgets/chat.dart → lib/widgets/chat/chat.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:ui';
import 'package:flutter/material.dart';

import '../models/models.dart';
import '../../models/models.dart';
import 'chatMessage.dart';

class ChatMessages extends StatelessWidget {
Expand Down
230 changes: 230 additions & 0 deletions lib/widgets/chat/chatBubble.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:papercups_flutter/models/models.dart';
import 'package:papercups_flutter/utils/colorMod.dart';
import 'package:papercups_flutter/widgets/chat/attachment.dart';
import 'package:papercups_flutter/widgets/chat/timeWidget.dart';
import 'package:timeago/timeago.dart' as timeago;

import 'chatMessage.dart';

class ChatBubble extends StatelessWidget {
const ChatBubble({
Key? key,
required this.userSent,
required this.isFirst,
required this.widget,
required this.nextMsg,
required this.msg,
required this.isLast,
required this.isTimeSentVisible,
required this.maxWidth,
required this.text,
required this.longDay,
required this.conatinsAttachment,
}) : super(key: key);

final bool userSent;
final bool isFirst;
final ChatMessage widget;
final PapercupsMessage nextMsg;
final PapercupsMessage msg;
final bool isLast;
final bool isTimeSentVisible;
final double maxWidth;
final String text;
final String? longDay;
final bool conatinsAttachment;

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
userSent ? MainAxisAlignment.end : MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (!userSent)
Padding(
padding: EdgeInsets.only(
right: 14,
left: 14,
top: (isFirst) ? 15 : 4,
bottom: 5,
),
child: (widget.msgs!.length == 1 ||
nextMsg.userId != msg.userId ||
isLast)
? Container(
decoration: BoxDecoration(
color: widget.props.primaryColor,
gradient: widget.props.primaryGradient,
shape: BoxShape.circle,
),
child: CircleAvatar(
radius: 16,
backgroundColor: Colors.transparent,
backgroundImage: (msg.user!.profilePhotoUrl != null)
? NetworkImage(msg.user!.profilePhotoUrl!)
: null,
child: (msg.user!.profilePhotoUrl != null)
? null
: (msg.user != null && msg.user!.fullName == null)
? Text(
msg.user!.email!
.substring(0, 1)
.toUpperCase(),
style: TextStyle(color: widget.textColor),
)
: Text(
msg.user!.fullName!
.substring(0, 1)
.toUpperCase(),
style: TextStyle(color: widget.textColor),
),
),
)
: SizedBox(
width: 32,
),
),
if (userSent)
TimeWidget(
userSent: userSent,
msg: msg,
isVisible: isTimeSentVisible,
),
Container(
decoration: BoxDecoration(
color: userSent
? widget.props.primaryColor
: Theme.of(context).brightness == Brightness.light
? brighten(Theme.of(context).disabledColor, 80)
: Color(0xff282828),
gradient: userSent ? widget.props.primaryGradient : null,
borderRadius: BorderRadius.circular(4),
),
constraints: BoxConstraints(
maxWidth: maxWidth,
),
margin: EdgeInsets.only(
top: (isFirst) ? 15 : 4,
bottom: 4,
right: userSent ? 18 : 0,
),
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 14,
),
child: Column(
children: [
if (conatinsAttachment)
Attachment(userSent: userSent, props: widget.props),
MarkdownBody(
data: text,
styleSheet: MarkdownStyleSheet(
blockquote:
TextStyle(decoration: TextDecoration.underline),
p: TextStyle(
color: userSent
? widget.textColor
: Theme.of(context).textTheme.bodyText1!.color,
),
a: TextStyle(
color: userSent
? Colors.white
: Theme.of(context).textTheme.bodyText1!.color,
),
blockquotePadding: EdgeInsets.only(bottom: 2),
blockquoteDecoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 1.5,
color: userSent
? widget.textColor
: Theme.of(context)
.textTheme
.bodyText1!
.color ??
Colors.white,
),
),
)
// blockquotePadding: EdgeInsets.only(left: 14),
// blockquoteDecoration: BoxDecoration(
// border: Border(
// left: BorderSide(color: Colors.grey[300]!, width: 4),
// )),
),
),
],
),
),
if (!userSent)
TimeWidget(
userSent: userSent,
msg: msg,
isVisible: isTimeSentVisible,
),
],
),
if (!userSent && ((nextMsg.userId != msg.userId) || (isLast)))
Padding(
padding: EdgeInsets.only(left: 16, bottom: 5, top: 4),
child: (msg.user!.fullName == null)
? Text(
msg.user!.email!,
style: TextStyle(
color: Theme.of(context).disabledColor.withOpacity(0.5),
fontSize: 14,
),
)
: Text(
msg.user!.fullName!,
style: TextStyle(
color: Theme.of(context).disabledColor.withOpacity(0.5),
fontSize: 14,
),
)),
if (userSent && isLast)
Container(
width: double.infinity,
margin: const EdgeInsets.only(
bottom: 4,
left: 18,
right: 18,
),
child: Text(
widget.sending
? widget.sendingText
: "${widget.sentText} ${timeago.format(msg.createdAt!)}",
textAlign: TextAlign.end,
style: TextStyle(color: Colors.grey),
),
),
if (isLast || nextMsg.userId != msg.userId)
SizedBox(
height: 10,
),
if (longDay != null)
IgnorePointer(
ignoring: true,
child: Container(
margin: EdgeInsets.all(15),
width: double.infinity,
child: Text(
longDay!,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey,
),
),
),
),
],
);
}
}
Loading

0 comments on commit 983b6b4

Please sign in to comment.