fluffychat/lib/components/content_banner.dart

88 lines
2.7 KiB
Dart
Raw Normal View History

2020-01-01 19:10:13 +01:00
import 'package:cached_network_image/cached_network_image.dart';
import 'package:famedlysdk/famedlysdk.dart';
2020-02-16 12:35:04 +01:00
import 'package:fluffychat/views/image_viewer.dart';
2020-01-01 19:10:13 +01:00
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'matrix.dart';
class ContentBanner extends StatelessWidget {
final MxContent mxContent;
final double height;
final IconData defaultIcon;
final bool loading;
2020-01-19 15:07:42 +01:00
final Function onEdit;
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,
2020-01-01 19:10:13 +01:00
Key key})
: super(key: key);
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final int bannerSize =
(mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt();
final String src = mxContent.getThumbnail(
Matrix.of(context).client,
width: bannerSize,
height: bannerSize,
method: ThumbnailMethod.scale,
);
return InkWell(
2020-01-17 11:42:48 +01:00
onTap: () => mxContent.mxc?.isNotEmpty ?? false
2020-02-16 12:35:04 +01:00
? ImageViewer.show(context, mxContent)
2020-01-17 11:42:48 +01:00
: null,
child: Container(
2020-02-16 10:42:59 +01:00
height: 300,
2020-01-19 15:07:42 +01:00
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
),
child: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
2020-02-16 10:42:59 +01:00
child: Opacity(
opacity: 0.75,
child: !loading
? mxContent.mxc?.isNotEmpty ?? false
? kIsWeb
? Image.network(
src,
height: 300,
fit: BoxFit.cover,
)
: CachedNetworkImage(
imageUrl: src,
height: 300,
fit: BoxFit.cover,
)
: Icon(defaultIcon, size: 300)
: Icon(defaultIcon, size: 300),
),
2020-01-19 15:07:42 +01:00
),
if (this.onEdit != null)
Container(
margin: EdgeInsets.all(8),
alignment: Alignment.bottomRight,
child: FloatingActionButton(
mini: true,
backgroundColor: Theme.of(context).primaryColor,
2020-02-16 13:57:51 +01:00
child: Icon(Icons.camera_alt),
2020-01-19 15:07:42 +01:00
onPressed: onEdit,
),
),
],
),
),
2020-01-01 19:10:13 +01:00
);
}
}