fluffychat/lib/widgets/content_banner.dart

78 lines
2.1 KiB
Dart
Raw Normal View History

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