feat: Added file attachment to pick attachment section

This commit is contained in:
Deven Joshi
2020-12-03 11:39:38 +01:00
committed by Salvatore Giordano
parent 895497290c
commit 922208224d
3 changed files with 109 additions and 65 deletions
+9 -1
View File
@@ -6,11 +6,13 @@ import 'package:stream_chat_flutter/src/utils.dart';
class FileAttachment extends StatelessWidget { class FileAttachment extends StatelessWidget {
final Attachment attachment; final Attachment attachment;
final Size size; final Size size;
final Widget trailing;
const FileAttachment({ const FileAttachment({
Key key, Key key,
@required this.attachment, @required this.attachment,
this.size, this.size,
this.trailing,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -22,8 +24,13 @@ class FileAttachment extends StatelessWidget {
}, },
child: Container( child: Container(
width: size?.width ?? 100, width: size?.width ?? 100,
margin: trailing != null ? EdgeInsets.only(top: 4.0) : null,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: trailing != null ? BorderRadius.circular(16.0) : null,
border: trailing != null
? Border.fromBorderSide(BorderSide(color: Color(0xFFE6E6E6)))
: null,
), ),
child: ListTile( child: ListTile(
dense: true, dense: true,
@@ -45,7 +52,8 @@ class FileAttachment extends StatelessWidget {
color: Colors.black.withOpacity(0.5), color: Colors.black.withOpacity(0.5),
), ),
), ),
trailing: IconButton( trailing: trailing ??
IconButton(
icon: StreamSvgIcon.cloud_download( icon: StreamSvgIcon.cloud_download(
color: Colors.black, color: Colors.black,
), ),
+31 -3
View File
@@ -1201,11 +1201,35 @@ class MessageInputState extends State<MessageInput> {
Widget _buildAttachments() { Widget _buildAttachments() {
return _attachments.isEmpty return _attachments.isEmpty
? Container() ? Container()
: LimitedBox( : Column(
children: [
..._attachments
.where((e) => e.attachment.type == 'file')
.map(
(e) => FileAttachment(
attachment: e.attachment,
size: Size(
MediaQuery.of(context).size.width * 0.6,
MediaQuery.of(context).size.height * 0.3,
),
trailing: IconButton(
icon: StreamSvgIcon.close_small(),
onPressed: () {
setState(() {
_attachments.remove(e);
});
},
),
),
)
.toList(),
if (_attachments.any((e) => e.attachment.type != 'file'))
LimitedBox(
maxHeight: 104.0, maxHeight: 104.0,
child: ListView( child: ListView(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
children: _attachments children: _attachments
.where((e) => e.attachment.type != 'file')
.map( .map(
(attachment) => Padding( (attachment) => Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@@ -1227,8 +1251,10 @@ class MessageInputState extends State<MessageInput> {
: Positioned.fill( : Positioned.fill(
child: Center( child: Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding:
child: CircularProgressIndicator(), const EdgeInsets.all(16.0),
child:
CircularProgressIndicator(),
), ),
), ),
), ),
@@ -1239,6 +1265,8 @@ class MessageInputState extends State<MessageInput> {
) )
.toList(), .toList(),
), ),
),
],
); );
} }
+31 -23
View File
@@ -225,6 +225,9 @@ class _MessageWidgetState extends State<MessageWidget> {
var user = StreamChat.of(context).user; var user = StreamChat.of(context).user;
bool hasFiles =
widget.message.attachments.any((element) => element.type == 'file');
return Portal( return Portal(
child: Padding( child: Padding(
padding: widget.padding ?? EdgeInsets.all(8), padding: widget.padding ?? EdgeInsets.all(8),
@@ -298,33 +301,38 @@ class _MessageWidgetState extends State<MessageWidget> {
), ),
) )
: Container( : Container(
decoration: BoxDecoration( decoration: widget.message.attachments
borderRadius: BorderRadius.only( .where((element) =>
topLeft: Radius.circular(8.0), element.type == 'file')
topRight: Radius.circular(8.0), .isEmpty
bottomRight: Radius.circular(8.0), ? null
: BoxDecoration(
borderRadius:
BorderRadius.only(
topLeft:
Radius.circular(8.0),
topRight:
Radius.circular(8.0),
bottomRight:
Radius.circular(8.0),
), ),
border: Border.fromBorderSide( border: hasFiles
? Border.fromBorderSide(
BorderSide( BorderSide(
color: Color(0xFFE6E6E6), color:
)), Color(0xFFE6E6E6),
color: widget.message.attachments ))
.where((element) => : null,
element.type == 'file') color: hasFiles
.isEmpty ? (user.id ==
? Colors.transparent widget.message
: (user.id == .user.id
widget.message.user.id
? Color(0xFFE6E6E6) ? Color(0xFFE6E6E6)
: Colors.white), : Colors.white)
: Colors.transparent,
), ),
padding: EdgeInsets.all(widget padding: EdgeInsets.all(
.message.attachments hasFiles ? 2.0 : 0.0),
.where((element) =>
element.type == 'file')
.isEmpty
? 0.0
: 2.0),
child: Column( child: Column(
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,