FurryChat/lib/components/content_banner.dart

79 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2020-01-01 18:10:13 +00:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
2020-04-08 10:38:52 +00:00
import 'package:flutter_advanced_networkimage/provider.dart';
2020-01-01 18:10:13 +00:00
import 'matrix.dart';
class ContentBanner extends StatelessWidget {
2020-04-28 12:11:56 +00:00
final Uri mxContent;
2020-01-01 18:10:13 +00:00
final double height;
final IconData defaultIcon;
final bool loading;
2020-01-19 14:07:42 +00:00
final Function onEdit;
2020-01-01 18:10:13 +00:00
const ContentBanner(this.mxContent,
{this.height = 400,
this.defaultIcon = Icons.people_outline,
this.loading = false,
2020-01-19 14:07:42 +00:00
this.onEdit,
2020-01-01 18:10:13 +00:00
Key key})
: super(key: key);
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
2020-05-13 13:58:59 +00:00
final bannerSize =
2020-01-01 18:10:13 +00:00
(mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt();
2020-05-13 13:58:59 +00:00
final src = mxContent?.getThumbnail(
2020-01-01 18:10:13 +00:00
Matrix.of(context).client,
width: bannerSize,
height: bannerSize,
method: ThumbnailMethod.scale,
);
2020-04-08 10:38:52 +00:00
return Container(
height: 300,
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: 0.75,
child: !loading
2020-04-28 12:11:56 +00:00
? mxContent != null
2020-04-08 10:38:52 +00:00
? Image(
height: 300,
fit: BoxFit.cover,
2020-05-15 19:50:44 +00:00
image: AdvancedNetworkImage(
src,
useDiskCache: !kIsWeb,
),
2020-04-08 10:38:52 +00:00
)
: Icon(defaultIcon, size: 300)
: Icon(defaultIcon, size: 300),
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(
margin: EdgeInsets.all(8),
alignment: Alignment.bottomRight,
child: FloatingActionButton(
mini: true,
backgroundColor: Theme.of(context).primaryColor,
child: Icon(Icons.camera_alt),
onPressed: onEdit,
2020-01-19 14:07:42 +00:00
),
2020-04-08 10:38:52 +00:00
),
],
),
2020-01-01 18:10:13 +00:00
);
}
}