fix: fix widget implementation in user avatar
parent
4e22605ceb
commit
405362b510
|
@ -5,67 +5,55 @@ import "../../blocs/heartbeat_bloc.dart";
|
|||
|
||||
class UserAvatar extends StatefulWidget {
|
||||
final User user;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double radius;
|
||||
final bloc;
|
||||
|
||||
UserAvatar ({ @required this.user });
|
||||
UserAvatar(
|
||||
{@required this.user,
|
||||
this.padding: const EdgeInsets.all(0.0),
|
||||
this.radius: 20.0})
|
||||
: bloc = HeartbeatReceiverBloc(user.id);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _UserAvatarState(user: this.user);
|
||||
return _UserAvatarState();
|
||||
}
|
||||
}
|
||||
|
||||
class _UserAvatarState extends State<UserAvatar> {
|
||||
final User user;
|
||||
final bloc;
|
||||
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double radius;
|
||||
|
||||
_UserAvatarState({
|
||||
@required this.user,
|
||||
this.padding: const EdgeInsets.all(0.0),
|
||||
this.radius: 20.0,
|
||||
}) : bloc = HeartbeatReceiverBloc(user.id);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
bloc.dispose();
|
||||
widget.bloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: padding,
|
||||
padding: widget.padding,
|
||||
child: Stack(alignment: Alignment.bottomRight, children: <Widget>[
|
||||
CircleAvatar(
|
||||
backgroundColor: _stringToColor(user.lastName),
|
||||
backgroundColor: _stringToColor(widget.user.lastName),
|
||||
child: Text(
|
||||
user.firstName[0].toUpperCase() +
|
||||
user.lastName[0].toUpperCase(),
|
||||
widget.user.firstName[0].toUpperCase() +
|
||||
widget.user.lastName[0].toUpperCase(),
|
||||
style: Theme.of(context).accentTextTheme.title,
|
||||
),
|
||||
radius: radius),
|
||||
StreamBuilder (
|
||||
stream: bloc.colours,
|
||||
builder: (context, AsyncSnapshot<Color> snapshot) {
|
||||
Color colour = Color.fromARGB(255, 158, 158, 158);
|
||||
if (snapshot.hasData) {
|
||||
colour = snapshot.data;
|
||||
}
|
||||
return Container(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
decoration: BoxDecoration(
|
||||
color: colour,
|
||||
shape: BoxShape.circle));
|
||||
}
|
||||
),
|
||||
radius: widget.radius),
|
||||
StreamBuilder(
|
||||
stream: widget.bloc.colours,
|
||||
builder: (context, AsyncSnapshot<Color> snapshot) {
|
||||
Color colour = Color.fromARGB(255, 158, 158, 158);
|
||||
if (snapshot.hasData) {
|
||||
colour = snapshot.data;
|
||||
}
|
||||
return Container(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
decoration:
|
||||
BoxDecoration(color: colour, shape: BoxShape.circle));
|
||||
}),
|
||||
]));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue