mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-17 08:48:11 +08:00
70 lines
2.2 KiB
Dart
70 lines
2.2 KiB
Dart
/*
|
|
* @Author : Linloir
|
|
* @Date : 2022-10-13 21:49:53
|
|
* @LastEditTime : 2022-10-13 22:17:17
|
|
* @Description :
|
|
*/
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:tcp_client/common/avatar/cubit/avatar_cubit.dart';
|
|
import 'package:tcp_client/common/avatar/cubit/avatar_state.dart';
|
|
import 'package:tcp_client/repositories/user_repository/user_repository.dart';
|
|
|
|
class UserAvatar extends StatelessWidget {
|
|
const UserAvatar({required this.userid, super.key});
|
|
|
|
final int userid;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<AvatarCubit, AvatarState>(
|
|
bloc: AvatarCubit(
|
|
userid: userid,
|
|
userRepository: context.read<UserRepository>()
|
|
),
|
|
builder: (context, state) {
|
|
if(state.userInfo.avatarEncoded == null) {
|
|
return Container(
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[800],
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
boxShadow: [BoxShadow(blurRadius: 10.0, color: Colors.grey[850]!.withOpacity(0.15))]
|
|
),
|
|
child: Text(
|
|
state.userInfo.userName[0],
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w300,
|
|
color: Colors.white,
|
|
shadows: [Shadow(blurRadius: 5.0, color: Colors.white.withOpacity(0.15))]
|
|
),
|
|
),
|
|
);
|
|
}
|
|
else {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
boxShadow: [BoxShadow(blurRadius: 10.0, color: Colors.grey[850]!.withOpacity(0.15))]
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
child: OverflowBox(
|
|
alignment: Alignment.center,
|
|
child: FittedBox(
|
|
fit: BoxFit.fitWidth,
|
|
child: Image.memory(base64.decode(state.userInfo.avatarEncoded!)),
|
|
),
|
|
)
|
|
),
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|