mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-17 00:38:11 +08:00
New Feature
- User Avatar!!
This commit is contained in:
parent
ce714e5820
commit
a5d5fe5eef
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-13 21:49:53
|
||||
* @LastEditTime : 2022-10-14 10:32:50
|
||||
* @LastEditTime : 2022-10-20 11:52:12
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -17,11 +17,13 @@ class UserAvatar extends StatelessWidget {
|
||||
const UserAvatar({
|
||||
required this.userid,
|
||||
this.size = 48,
|
||||
this.onTap,
|
||||
super.key
|
||||
});
|
||||
|
||||
final int userid;
|
||||
final double size;
|
||||
final void Function()? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -35,19 +37,30 @@ class UserAvatar extends StatelessWidget {
|
||||
return Container(
|
||||
width: size,
|
||||
height: size,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[600],
|
||||
borderRadius: BorderRadius.circular(5.0),
|
||||
boxShadow: [BoxShadow(blurRadius: 10.0, color: Colors.grey[850]!.withOpacity(0.15))]
|
||||
),
|
||||
child: Text(
|
||||
state.userInfo.userName[0].toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 24 * (size / 48),
|
||||
fontWeight: FontWeight.w300,
|
||||
color: Colors.white,
|
||||
shadows: [Shadow(blurRadius: 5.0, color: Colors.white.withOpacity(0.15))]
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(5.0),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
state.userInfo.userName[0].toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 24 * (size / 48),
|
||||
fontWeight: FontWeight.w300,
|
||||
color: Colors.white,
|
||||
shadows: [Shadow(blurRadius: 5.0, color: Colors.white.withOpacity(0.15))]
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -62,13 +75,19 @@ class UserAvatar extends StatelessWidget {
|
||||
),
|
||||
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!)),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: OverflowBox(
|
||||
alignment: Alignment.center,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: Image.memory(base64.decode(state.userInfo.avatarEncoded!)),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,20 +1,28 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-12 23:36:12
|
||||
* @LastEditTime : 2022-10-14 12:10:34
|
||||
* @LastEditTime : 2022-10-20 11:45:15
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tcp_client/common/avatar/avatar.dart';
|
||||
import 'package:tcp_client/common/username/username.dart';
|
||||
import 'package:tcp_client/home/cubit/home_cubit.dart';
|
||||
import 'package:tcp_client/home/view/profile_page/cubit/log_out_cubit.dart';
|
||||
import 'package:tcp_client/home/view/profile_page/cubit/log_out_state.dart';
|
||||
import 'package:tcp_client/home/view/profile_page/view/log_out_button.dart';
|
||||
import 'package:tcp_client/login/login_page.dart';
|
||||
import 'package:tcp_client/repositories/common_models/userinfo.dart';
|
||||
import 'package:tcp_client/repositories/local_service_repository/local_service_repository.dart';
|
||||
import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart';
|
||||
import 'package:tcp_client/repositories/tcp_repository/tcp_repository.dart';
|
||||
import 'package:tcp_client/repositories/user_repository/user_repository.dart';
|
||||
|
||||
class MyProfilePage extends StatelessWidget {
|
||||
const MyProfilePage({
|
||||
@ -62,7 +70,29 @@ class MyProfilePage extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
UserAvatar(userid: userID, size: 96,),
|
||||
UserAvatar(
|
||||
userid: userID,
|
||||
size: 96,
|
||||
onTap: () async {
|
||||
var homeCubit = context.read<HomeCubit>();
|
||||
var userInfo = context.read<UserRepository>().getUserInfo(userid: userID);
|
||||
homeCubit.localServiceRepository.pickFile(FileType.image).then((img) async {
|
||||
if(img != null) {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var token = pref.getInt('token');
|
||||
var newRequest = ModifyProfileRequest(
|
||||
userInfo: UserInfo(
|
||||
userid: userID,
|
||||
username: userInfo.userName,
|
||||
avatar: base64.encode(await img.readAsBytes())
|
||||
),
|
||||
token: token
|
||||
);
|
||||
homeCubit.tcpRepository.pushRequest(newRequest);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 48,),
|
||||
UserNameText(
|
||||
userid: userID,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-14 08:54:32
|
||||
* @LastEditTime : 2022-10-20 11:28:22
|
||||
* @LastEditTime : 2022-10-20 11:30:46
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -24,7 +24,6 @@ class UserProfileCubit extends Cubit<UserProfileState> {
|
||||
final TCPRepository tcpRepository;
|
||||
|
||||
Future<void> updateContactStatus() async {
|
||||
var curUserId = (await SharedPreferences.getInstance()).getInt('userid');
|
||||
if(userID == (await SharedPreferences.getInstance()).getInt('userid')) {
|
||||
emit(const UserProfileState(status: ContactStatus.none));
|
||||
return;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-13 20:18:14
|
||||
* @LastEditTime : 2022-10-13 21:26:16
|
||||
* @LastEditTime : 2022-10-20 11:50:26
|
||||
* @Description : Repository to cache user info
|
||||
*/
|
||||
|
||||
@ -40,6 +40,12 @@ class UserRepository {
|
||||
_userInfoStreamController.add(response.userInfo!);
|
||||
localServiceRepository.storeUserInfo(userInfo: response.userInfo!);
|
||||
}
|
||||
else if(response.type == TCPResponseType.modifyProfile && response.status == TCPResponseStatus.ok) {
|
||||
response as ModifyProfileResponse;
|
||||
users.update(response.userInfo!.userID, (value) => response.userInfo!, ifAbsent: () => response.userInfo!);
|
||||
_userInfoStreamController.add(response.userInfo!);
|
||||
localServiceRepository.storeUserInfo(userInfo: response.userInfo!);
|
||||
}
|
||||
}
|
||||
|
||||
//Fetch user info
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user