feat: Added file attachment to pick attachment section
This commit is contained in:
committed by
Salvatore Giordano
parent
895497290c
commit
922208224d
@@ -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,14 +52,15 @@ class FileAttachment extends StatelessWidget {
|
|||||||
color: Colors.black.withOpacity(0.5),
|
color: Colors.black.withOpacity(0.5),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
trailing: IconButton(
|
trailing: trailing ??
|
||||||
icon: StreamSvgIcon.cloud_download(
|
IconButton(
|
||||||
color: Colors.black,
|
icon: StreamSvgIcon.cloud_download(
|
||||||
),
|
color: Colors.black,
|
||||||
onPressed: () {
|
),
|
||||||
launchURL(context, attachment.assetUrl);
|
onPressed: () {
|
||||||
},
|
launchURL(context, attachment.assetUrl);
|
||||||
),
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+61
-33
@@ -1201,44 +1201,72 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
Widget _buildAttachments() {
|
Widget _buildAttachments() {
|
||||||
return _attachments.isEmpty
|
return _attachments.isEmpty
|
||||||
? Container()
|
? Container()
|
||||||
: LimitedBox(
|
: Column(
|
||||||
maxHeight: 104.0,
|
children: [
|
||||||
child: ListView(
|
..._attachments
|
||||||
scrollDirection: Axis.horizontal,
|
.where((e) => e.attachment.type == 'file')
|
||||||
children: _attachments
|
|
||||||
.map(
|
.map(
|
||||||
(attachment) => Padding(
|
(e) => FileAttachment(
|
||||||
padding: const EdgeInsets.all(8.0),
|
attachment: e.attachment,
|
||||||
child: ClipRRect(
|
size: Size(
|
||||||
borderRadius: BorderRadius.circular(10),
|
MediaQuery.of(context).size.width * 0.6,
|
||||||
child: Stack(
|
MediaQuery.of(context).size.height * 0.3,
|
||||||
children: <Widget>[
|
),
|
||||||
AspectRatio(
|
trailing: IconButton(
|
||||||
aspectRatio: 1.0,
|
icon: StreamSvgIcon.close_small(),
|
||||||
child: Container(
|
onPressed: () {
|
||||||
height: 104,
|
setState(() {
|
||||||
width: 104,
|
_attachments.remove(e);
|
||||||
child: _buildAttachment(attachment),
|
});
|
||||||
),
|
},
|
||||||
),
|
|
||||||
_buildRemoveButton(attachment),
|
|
||||||
attachment.uploaded
|
|
||||||
? SizedBox()
|
|
||||||
: Positioned.fill(
|
|
||||||
child: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
if (_attachments.any((e) => e.attachment.type != 'file'))
|
||||||
|
LimitedBox(
|
||||||
|
maxHeight: 104.0,
|
||||||
|
child: ListView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
children: _attachments
|
||||||
|
.where((e) => e.attachment.type != 'file')
|
||||||
|
.map(
|
||||||
|
(attachment) => Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
child: Stack(
|
||||||
|
children: <Widget>[
|
||||||
|
AspectRatio(
|
||||||
|
aspectRatio: 1.0,
|
||||||
|
child: Container(
|
||||||
|
height: 104,
|
||||||
|
width: 104,
|
||||||
|
child: _buildAttachment(attachment),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_buildRemoveButton(attachment),
|
||||||
|
attachment.uploaded
|
||||||
|
? SizedBox()
|
||||||
|
: Positioned.fill(
|
||||||
|
child: Center(
|
||||||
|
child: Padding(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.all(16.0),
|
||||||
|
child:
|
||||||
|
CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+32
-24
@@ -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(
|
|
||||||
topLeft: Radius.circular(8.0),
|
|
||||||
topRight: Radius.circular(8.0),
|
|
||||||
bottomRight: Radius.circular(8.0),
|
|
||||||
),
|
|
||||||
border: Border.fromBorderSide(
|
|
||||||
BorderSide(
|
|
||||||
color: Color(0xFFE6E6E6),
|
|
||||||
)),
|
|
||||||
color: widget.message.attachments
|
|
||||||
.where((element) =>
|
|
||||||
element.type == 'file')
|
|
||||||
.isEmpty
|
|
||||||
? Colors.transparent
|
|
||||||
: (user.id ==
|
|
||||||
widget.message.user.id
|
|
||||||
? Color(0xFFE6E6E6)
|
|
||||||
: Colors.white),
|
|
||||||
),
|
|
||||||
padding: EdgeInsets.all(widget
|
|
||||||
.message.attachments
|
|
||||||
.where((element) =>
|
.where((element) =>
|
||||||
element.type == 'file')
|
element.type == 'file')
|
||||||
.isEmpty
|
.isEmpty
|
||||||
? 0.0
|
? null
|
||||||
: 2.0),
|
: BoxDecoration(
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.only(
|
||||||
|
topLeft:
|
||||||
|
Radius.circular(8.0),
|
||||||
|
topRight:
|
||||||
|
Radius.circular(8.0),
|
||||||
|
bottomRight:
|
||||||
|
Radius.circular(8.0),
|
||||||
|
),
|
||||||
|
border: hasFiles
|
||||||
|
? Border.fromBorderSide(
|
||||||
|
BorderSide(
|
||||||
|
color:
|
||||||
|
Color(0xFFE6E6E6),
|
||||||
|
))
|
||||||
|
: null,
|
||||||
|
color: hasFiles
|
||||||
|
? (user.id ==
|
||||||
|
widget.message
|
||||||
|
.user.id
|
||||||
|
? Color(0xFFE6E6E6)
|
||||||
|
: Colors.white)
|
||||||
|
: Colors.transparent,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(
|
||||||
|
hasFiles ? 2.0 : 0.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
CrossAxisAlignment.start,
|
CrossAxisAlignment.start,
|
||||||
|
|||||||
Reference in New Issue
Block a user