2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-09-07 17:08:01 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
import 'matrix.dart';
|
|
|
|
|
|
|
|
class ContentBanner extends StatelessWidget {
|
2020-04-28 14:11:56 +02:00
|
|
|
final Uri mxContent;
|
2020-01-01 19:10:13 +01:00
|
|
|
final double height;
|
|
|
|
final IconData defaultIcon;
|
|
|
|
final bool loading;
|
2020-01-19 15:07:42 +01:00
|
|
|
final Function onEdit;
|
2021-01-20 20:27:09 +01:00
|
|
|
final Client client;
|
2021-02-03 15:47:51 +01:00
|
|
|
final double opacity;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
const ContentBanner(this.mxContent,
|
|
|
|
{this.height = 400,
|
|
|
|
this.defaultIcon = Icons.people_outline,
|
|
|
|
this.loading = false,
|
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,
|
2020-01-01 19:10:13 +01:00
|
|
|
Key key})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final mediaQuery = MediaQuery.of(context);
|
2020-05-13 15:58:59 +02:00
|
|
|
final bannerSize =
|
2020-01-01 19:10:13 +01:00
|
|
|
(mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt();
|
2020-05-13 15:58:59 +02:00
|
|
|
final src = mxContent?.getThumbnail(
|
2021-01-20 20:27:09 +01:00
|
|
|
client ?? Matrix.of(context).client,
|
2020-01-01 19:10:13 +01:00
|
|
|
width: bannerSize,
|
|
|
|
height: bannerSize,
|
|
|
|
method: ThumbnailMethod.scale,
|
2020-12-29 10:43:32 +01:00
|
|
|
animated: true,
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
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(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
),
|
|
|
|
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,
|
2021-05-31 19:33:40 +02:00
|
|
|
child:
|
|
|
|
(!loading && mxContent != null && mxContent.host.isNotEmpty)
|
|
|
|
? CachedNetworkImage(
|
|
|
|
imageUrl: src.toString(),
|
|
|
|
height: 300,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
)
|
|
|
|
: Icon(defaultIcon, size: 200),
|
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(
|
|
|
|
margin: EdgeInsets.all(8),
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: FloatingActionButton(
|
|
|
|
mini: true,
|
|
|
|
onPressed: onEdit,
|
2021-05-31 19:33:40 +02:00
|
|
|
backgroundColor: Theme.of(context).backgroundColor,
|
|
|
|
foregroundColor: Theme.of(context).textTheme.bodyText1.color,
|
2021-03-04 12:28:06 +01:00
|
|
|
child: Icon(Icons.camera_alt_outlined),
|
2020-01-19 15:07:42 +01:00
|
|
|
),
|
2020-04-08 12:38:52 +02:00
|
|
|
),
|
|
|
|
],
|
2020-01-17 11:08:12 +01:00
|
|
|
),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|