fluffychat/lib/widgets/content_banner.dart

83 lines
2.3 KiB
Dart
Raw Normal View History

2020-01-01 18:10:13 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2020-01-01 18:10:13 +00:00
import 'package:fluffychat/widgets/mxc_image.dart';
2020-01-01 18:10:13 +00:00
class ContentBanner extends StatelessWidget {
2022-01-29 11:35:03 +00:00
final Uri? mxContent;
2020-01-01 18:10:13 +00:00
final double height;
final IconData defaultIcon;
2022-01-28 17:21:20 +00:00
final void Function()? onEdit;
final Client? client;
2021-02-03 14:47:51 +00:00
final double opacity;
final WidgetBuilder? placeholder;
2020-01-01 18:10:13 +00:00
const ContentBanner({
this.mxContent,
this.height = 400,
this.defaultIcon = Icons.account_circle_outlined,
this.onEdit,
this.client,
this.opacity = 0.75,
this.placeholder,
super.key,
});
2020-01-01 18:10:13 +00:00
@override
Widget build(BuildContext context) {
2022-01-28 17:21:20 +00:00
final onEdit = this.onEdit;
2020-04-08 10:38:52 +00:00
return Container(
2021-02-03 14:47:51 +00:00
height: height,
2020-04-08 10:38:52 +00:00
alignment: Alignment.center,
decoration: BoxDecoration(
2022-07-08 08:13:44 +00:00
color: Theme.of(context).colorScheme.secondaryContainer,
2020-04-08 10:38:52 +00:00
),
child: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
child: Opacity(
2021-02-03 14:47:51 +00:00
opacity: opacity,
2022-12-30 13:37:13 +00:00
child: mxContent == null
? Center(
child: Icon(
defaultIcon,
color:
Theme.of(context).colorScheme.onSecondaryContainer,
size: 128,
2022-12-30 08:04:46 +00:00
),
2022-12-30 13:37:13 +00:00
)
: MxcImage(
key: Key(mxContent?.toString() ?? 'NoKey'),
uri: mxContent,
animated: true,
fit: BoxFit.cover,
placeholder: placeholder,
2022-12-30 13:37:13 +00:00
height: 400,
width: 800,
),
2020-01-19 14:07:42 +00:00
),
2020-04-08 10:38:52 +00:00
),
2020-05-13 13:58:59 +00:00
if (onEdit != null)
2020-04-08 10:38:52 +00:00
Container(
2021-10-14 16:09:30 +00:00
margin: const EdgeInsets.all(8),
2020-04-08 10:38:52 +00:00
alignment: Alignment.bottomRight,
child: FloatingActionButton(
mini: true,
2022-12-30 13:37:13 +00:00
heroTag: null,
2020-04-08 10:38:52 +00:00
onPressed: onEdit,
2023-01-26 08:47:30 +00:00
backgroundColor: Theme.of(context).colorScheme.background,
foregroundColor: Theme.of(context).textTheme.bodyLarge?.color,
2021-11-14 12:24:01 +00:00
child: const Icon(Icons.camera_alt_outlined),
2020-01-19 14:07:42 +00:00
),
2020-04-08 10:38:52 +00:00
),
],
),
2020-01-01 18:10:13 +00:00
);
}
}