2022-02-05 00:57:31 +00:00
|
|
|
import 'dart:io';
|
2022-02-07 23:12:36 +00:00
|
|
|
import 'dart:math';
|
2022-02-05 00:57:31 +00:00
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-07 01:40:10 +00:00
|
|
|
import 'package:cwtch/themes/opaque.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../settings.dart';
|
|
|
|
|
|
|
|
class ProfileImage extends StatefulWidget {
|
2021-07-13 21:46:47 +00:00
|
|
|
ProfileImage(
|
2022-02-07 23:12:36 +00:00
|
|
|
{required this.imagePath,
|
|
|
|
required this.diameter,
|
|
|
|
required this.border,
|
|
|
|
this.badgeCount = 0,
|
|
|
|
required this.badgeColor,
|
|
|
|
required this.badgeTextColor,
|
|
|
|
this.maskOut = false,
|
|
|
|
this.tooltip = "",
|
|
|
|
this.badgeEdit = false});
|
2021-06-24 23:10:45 +00:00
|
|
|
final double diameter;
|
|
|
|
final String imagePath;
|
|
|
|
final Color border;
|
|
|
|
final int badgeCount;
|
|
|
|
final Color badgeColor;
|
|
|
|
final Color badgeTextColor;
|
|
|
|
final bool maskOut;
|
2022-02-07 23:12:36 +00:00
|
|
|
final bool badgeEdit;
|
2021-07-09 22:16:06 +00:00
|
|
|
final String tooltip;
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_ProfileImageState createState() => _ProfileImageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProfileImageState extends State<ProfileImage> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-02-05 00:57:31 +00:00
|
|
|
var file = new File(widget.imagePath);
|
|
|
|
var image = Image.file(
|
|
|
|
file,
|
2022-04-21 00:20:31 +00:00
|
|
|
cacheWidth: (4 * widget.diameter.floor()),
|
2021-07-09 22:16:06 +00:00
|
|
|
filterQuality: FilterQuality.medium,
|
2022-02-08 21:59:24 +00:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
alignment: Alignment.center,
|
2021-07-09 22:16:06 +00:00
|
|
|
// We need some theme specific blending here...we might want to consider making this a theme level attribute
|
|
|
|
colorBlendMode: !widget.maskOut
|
2021-12-10 04:22:55 +00:00
|
|
|
? Provider.of<Settings>(context).theme.mode == mode_dark
|
2021-07-13 21:46:47 +00:00
|
|
|
? BlendMode.softLight
|
|
|
|
: BlendMode.darken
|
2021-07-09 22:16:06 +00:00
|
|
|
: BlendMode.srcOut,
|
2021-12-10 04:22:55 +00:00
|
|
|
color: Provider.of<Settings>(context).theme.portraitBackgroundColor,
|
2022-02-08 21:59:24 +00:00
|
|
|
isAntiAlias: false,
|
2021-07-09 22:16:06 +00:00
|
|
|
width: widget.diameter,
|
|
|
|
height: widget.diameter,
|
2022-02-05 00:57:31 +00:00
|
|
|
errorBuilder: (context, error, stackTrace) {
|
|
|
|
// on android the above will fail for asset images, in which case try to load them the original way
|
|
|
|
return Image.asset(widget.imagePath,
|
|
|
|
filterQuality: FilterQuality.medium,
|
|
|
|
// We need some theme specific blending here...we might want to consider making this a theme level attribute
|
|
|
|
colorBlendMode: !widget.maskOut
|
|
|
|
? Provider.of<Settings>(context).theme.mode == mode_dark
|
|
|
|
? BlendMode.softLight
|
|
|
|
: BlendMode.darken
|
|
|
|
: BlendMode.srcOut,
|
|
|
|
color: Provider.of<Settings>(context).theme.portraitBackgroundColor,
|
|
|
|
isAntiAlias: true,
|
|
|
|
width: widget.diameter,
|
|
|
|
height: widget.diameter);
|
|
|
|
},
|
2021-07-09 22:16:06 +00:00
|
|
|
);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
return RepaintBoundary(
|
|
|
|
child: Stack(children: [
|
|
|
|
ClipOval(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
child: Container(
|
|
|
|
width: widget.diameter,
|
|
|
|
height: widget.diameter,
|
|
|
|
color: widget.border,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(2.0), //border size
|
2021-07-13 21:46:47 +00:00
|
|
|
child: ClipOval(clipBehavior: Clip.antiAlias, child: widget.tooltip == "" ? image : Tooltip(message: widget.tooltip, child: image))))),
|
2021-06-24 23:10:45 +00:00
|
|
|
Visibility(
|
2022-02-07 23:12:36 +00:00
|
|
|
visible: widget.badgeEdit || widget.badgeCount > 0,
|
2021-06-24 23:10:45 +00:00
|
|
|
child: Positioned(
|
|
|
|
bottom: 0.0,
|
|
|
|
right: 0.0,
|
|
|
|
child: CircleAvatar(
|
2022-02-07 23:12:36 +00:00
|
|
|
radius: max(10.0, widget.diameter / 6.0),
|
2021-06-24 23:10:45 +00:00
|
|
|
backgroundColor: widget.badgeColor,
|
2022-02-07 23:12:36 +00:00
|
|
|
child: widget.badgeEdit
|
|
|
|
? Icon(
|
|
|
|
Icons.edit,
|
|
|
|
color: widget.badgeTextColor,
|
|
|
|
)
|
|
|
|
: Text(widget.badgeCount > 99 ? "99+" : widget.badgeCount.toString(), style: TextStyle(color: widget.badgeTextColor, fontSize: 8.0)),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
|
|
|
)),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|