2024-11-09 04:04:03 +00:00
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gap/gap.dart';
|
2024-11-10 09:21:57 +00:00
|
|
|
import 'package:responsive_framework/responsive_framework.dart';
|
2024-11-09 04:04:03 +00:00
|
|
|
import 'package:surface/types/attachment.dart';
|
|
|
|
import 'package:surface/widgets/attachment/attachment_item.dart';
|
|
|
|
|
|
|
|
class AttachmentList extends StatelessWidget {
|
|
|
|
final List<SnAttachment> data;
|
|
|
|
final bool? bordered;
|
2024-11-13 16:20:59 +00:00
|
|
|
final double? maxHeight;
|
2024-11-14 14:21:13 +00:00
|
|
|
final EdgeInsets? listPadding;
|
2024-11-10 08:41:11 +00:00
|
|
|
const AttachmentList({
|
|
|
|
super.key,
|
|
|
|
required this.data,
|
|
|
|
this.bordered,
|
2024-11-13 16:20:59 +00:00
|
|
|
this.maxHeight,
|
2024-11-14 14:21:13 +00:00
|
|
|
this.listPadding,
|
2024-11-10 08:41:11 +00:00
|
|
|
});
|
2024-11-09 04:04:03 +00:00
|
|
|
|
2024-11-10 09:21:57 +00:00
|
|
|
static const BorderRadius kDefaultRadius =
|
|
|
|
BorderRadius.all(Radius.circular(8));
|
|
|
|
|
2024-11-09 04:04:03 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final borderSide = (bordered ?? false)
|
|
|
|
? BorderSide(width: 1, color: Theme.of(context).dividerColor)
|
|
|
|
: BorderSide.none;
|
|
|
|
|
|
|
|
if (data.isEmpty) return const SizedBox.shrink();
|
|
|
|
if (data.length == 1) {
|
2024-11-10 09:21:57 +00:00
|
|
|
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE)) {
|
2024-11-14 14:21:13 +00:00
|
|
|
return Padding(
|
|
|
|
// Single child list-like displaying
|
|
|
|
padding: listPadding ?? EdgeInsets.zero,
|
|
|
|
child: Container(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minWidth: 80,
|
|
|
|
maxHeight: maxHeight ?? double.infinity,
|
2024-11-10 09:21:57 +00:00
|
|
|
),
|
2024-11-14 14:21:13 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(top: borderSide, bottom: borderSide),
|
2024-11-10 09:21:57 +00:00
|
|
|
borderRadius: kDefaultRadius,
|
2024-11-14 14:21:13 +00:00
|
|
|
),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: data[0].metadata['ratio']?.toDouble() ?? 1,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: kDefaultRadius,
|
|
|
|
child: AttachmentItem(data: data[0], isExpandable: true),
|
|
|
|
),
|
2024-11-10 09:21:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-11-09 04:04:03 +00:00
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(top: borderSide, bottom: borderSide),
|
|
|
|
),
|
2024-11-10 09:21:57 +00:00
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: data[0].metadata['ratio']?.toDouble() ?? 1,
|
|
|
|
child: AttachmentItem(data: data[0], isExpandable: true),
|
|
|
|
),
|
2024-11-09 04:04:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Container(
|
2024-11-13 16:20:59 +00:00
|
|
|
constraints: BoxConstraints(maxHeight: maxHeight ?? 320),
|
2024-11-09 04:04:03 +00:00
|
|
|
child: ScrollConfiguration(
|
|
|
|
behavior: _AttachmentListScrollBehavior(),
|
|
|
|
child: ListView.separated(
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: data.length,
|
|
|
|
itemBuilder: (context, idx) {
|
|
|
|
return Container(
|
2024-11-10 08:41:11 +00:00
|
|
|
constraints: BoxConstraints(
|
2024-11-14 14:21:13 +00:00
|
|
|
minWidth: 80,
|
2024-11-13 16:20:59 +00:00
|
|
|
maxHeight: maxHeight ?? double.infinity,
|
2024-11-10 08:41:11 +00:00
|
|
|
),
|
2024-11-09 04:04:03 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(top: borderSide, bottom: borderSide),
|
2024-11-10 09:21:57 +00:00
|
|
|
borderRadius: kDefaultRadius,
|
2024-11-09 04:04:03 +00:00
|
|
|
),
|
2024-11-10 08:41:11 +00:00
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: data[idx].metadata['ratio']?.toDouble() ?? 1,
|
|
|
|
child: ClipRRect(
|
2024-11-10 09:21:57 +00:00
|
|
|
borderRadius: kDefaultRadius,
|
|
|
|
child: AttachmentItem(data: data[idx], isExpandable: true),
|
2024-11-10 08:41:11 +00:00
|
|
|
),
|
2024-11-09 04:04:03 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorBuilder: (context, index) => const Gap(8),
|
2024-11-14 14:21:13 +00:00
|
|
|
padding: listPadding,
|
2024-11-09 04:04:03 +00:00
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AttachmentListScrollBehavior extends MaterialScrollBehavior {
|
|
|
|
@override
|
|
|
|
Set<PointerDeviceKind> get dragDevices => {
|
|
|
|
PointerDeviceKind.touch,
|
|
|
|
PointerDeviceKind.mouse,
|
|
|
|
};
|
|
|
|
}
|