You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/widgets/content_banner.dart

81 lines
2.3 KiB
Dart

import 'package:matrix/matrix.dart';
5 years ago
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
5 years ago
import 'matrix.dart';
class ContentBanner extends StatelessWidget {
5 years ago
final Uri mxContent;
5 years ago
final double height;
final IconData defaultIcon;
final bool loading;
final Function onEdit;
final Client client;
final double opacity;
5 years ago
const ContentBanner(this.mxContent,
{this.height = 400,
this.defaultIcon = Icons.people_outline,
this.loading = false,
this.onEdit,
this.client,
this.opacity = 0.75,
5 years ago
Key key})
: super(key: key);
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
5 years ago
final bannerSize =
5 years ago
(mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt();
5 years ago
final src = mxContent?.getThumbnail(
client ?? Matrix.of(context).client,
5 years ago
width: bannerSize,
height: bannerSize,
method: ThumbnailMethod.scale,
animated: true,
5 years ago
);
return Container(
height: height,
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(
opacity: opacity,
child:
(!loading && mxContent != null && mxContent.host.isNotEmpty)
? CachedNetworkImage(
imageUrl: src.toString(),
height: 300,
fit: BoxFit.cover,
)
: Icon(defaultIcon, size: 200),
),
),
5 years ago
if (onEdit != null)
Container(
margin: EdgeInsets.all(8),
alignment: Alignment.bottomRight,
child: FloatingActionButton(
mini: true,
onPressed: onEdit,
backgroundColor: Theme.of(context).backgroundColor,
foregroundColor: Theme.of(context).textTheme.bodyText1.color,
child: Icon(Icons.camera_alt_outlined),
),
),
],
),
5 years ago
);
}
}