内部存储 封装 改了一下小bug

This commit is contained in:
YangYuhao 2023-07-06 09:25:49 +08:00
parent 627d312240
commit 26a9982e9b
21 changed files with 450 additions and 228 deletions

View File

@ -1,6 +1,7 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../util/SharedPreferencesHelper.dart';
import 'state.dart'; import 'state.dart';
class AccountLogic extends GetxController { class AccountLogic extends GetxController {
@ -10,9 +11,15 @@ class AccountLogic extends GetxController {
void onInit() async{ void onInit() async{
super.onInit(); super.onInit();
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
photo = prefs.getString("photo")??""; // 使 SharedPreferences
print(photo.toString()); photo = sharedPreferences.getString(SharedPreferencesHelper.PHOTO);
update(); print(photo.toString());
update();
});
} }
} }

View File

@ -20,6 +20,7 @@ import '../../common/errorcode.dart';
import '../../network/api.dart'; import '../../network/api.dart';
import '../../network/dio_manager.dart'; import '../../network/dio_manager.dart';
import '../../router/app_routers.dart'; import '../../router/app_routers.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../../util/qiniu.dart'; import '../../util/qiniu.dart';
import '../login/complete_material/logic.dart'; import '../login/complete_material/logic.dart';
import '../select_circle/logic.dart'; import '../select_circle/logic.dart';
@ -52,11 +53,13 @@ class Call_outLogic extends GetxController {
// print(myConfigData.name); // print(myConfigData.name);
numbers.addAll(myConfigData); numbers.addAll(myConfigData);
circleName = numbers[0].name; circleName = numbers[0].name;
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
vip = prefs.getInt("vip") ?? 0; vip = sharedPreferences.getInt(SharedPreferencesHelper.VIP);
if (vip == 2) { if (vip == 2) {
isCheck = true; isCheck = true;
} }
});
update(); update();
} }
@ -143,9 +146,9 @@ class Call_outLogic extends GetxController {
// Navigator.pop(Get.context!, numbers); // Navigator.pop(Get.context!, numbers);
Get.back(); Get.back();
} else if (beandata.code == 30503) { } else if (beandata.code == 30503) {
if (beandata.data == null) { // if (beandata.data == null) {
return; // return;
} // }
showToast(beandata.msg); showToast(beandata.msg);
var callOutBean = BaseResponse<List<String>>.fromJson( var callOutBean = BaseResponse<List<String>>.fromJson(
data, data,
@ -368,7 +371,7 @@ class Call_outLogic extends GetxController {
} }
SmartDialog.showLoading(); SmartDialog.showLoading();
var path = await getApplicationSupportDirectoryPath(); var path = await getApplicationSupportDirectoryPath();
compressVideo(pickedFile!.path, path, (result) async { compressVideo(pickedFile.path, path, (result) async {
print(result); print(result);
videoPlayerController = VideoPlayerController.file( videoPlayerController = VideoPlayerController.file(
File(result), File(result),

View File

@ -83,9 +83,7 @@ class Call_outPage extends StatelessWidget {
Color(0xffD739EA) Color(0xffD739EA)
])), ])),
child: Text( child: Text(
logic.circleName != null logic.circleName ?? '',
? logic.circleName
: '',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp), fontSize: 12.sp),

View File

@ -1,4 +1,3 @@
import 'dart:ffi';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:circle_app/app/circle/logic.dart'; import 'package:circle_app/app/circle/logic.dart';
@ -12,8 +11,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart'; import 'package:get/get_core/src/get_main.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import '../../../util/SharedPreferencesHelper.dart';
class InfoListView extends StatefulWidget { class InfoListView extends StatefulWidget {
// Get.lazyPut(() => ListLogic()); // Get.lazyPut(() => ListLogic());
@ -141,14 +140,19 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
} }
void pushHomePage(Lists bean, String cicleId) async { void pushHomePage(Lists bean, String cicleId) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
int userId = prefs.getInt("userId") ?? 0; int userId = sharedPreferences.getInt(SharedPreferencesHelper.USERID);
if (bean.user!.id == userId) { if (bean.user!.id == userId) {
Get.toNamed(AppRoutes.UserInfoActivity); Get.toNamed(AppRoutes.UserInfoActivity);
} else { } else {
Get.toNamed(AppRoutes.UserInfoActivity, Get.toNamed(AppRoutes.UserInfoActivity,
arguments: bean.user!.id!.toString()); arguments: bean.user!.id!.toString());
} }
});
// if (bean.isQueen) { // if (bean.isQueen) {
// showJoinCiclePiker(cicleId); // showJoinCiclePiker(cicleId);
@ -166,9 +170,10 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextSpan descSpan; TextSpan descSpan;
// widget.bean.intro = widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro;
TextSpan span; TextSpan span;
if (widget.bean.intro.length > 60) { if (widget.bean.intro.length > 20) {
String truncatedText = widget.bean.intro.substring(0, 60); String truncatedText = widget.bean.intro.substring(0, 60)+"...";
descSpan = TextSpan( descSpan = TextSpan(
text: truncatedText, text: truncatedText,
style: TextStyle(color: Colors.white, fontSize: 10.sp), style: TextStyle(color: Colors.white, fontSize: 10.sp),
@ -192,9 +197,12 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
List<Widget> widgets = []; List<Widget> widgets = [];
int i = 0; int i = 0;
urlList.forEach((element) { urlList.forEach((element) {
if(widgets.length>2){
return;
}
widgets.add(Positioned( widgets.add(Positioned(
left: 15.sp * i, left: 15.sp * i,
child: circleWidget(element.avatar), child: circleWidget(element.avatar,element.id.toString()),
)); ));
i++; i++;
}); });
@ -266,7 +274,12 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
])), ])),
), ),
), ),
Container( GestureDetector(
behavior:HitTestBehavior.opaque,
onTap: (){
showToast("点个鸡毛,星哥还没做");
Get.toNamed(AppRoutes.FriendsActivity,arguments: '3');
},
child: Row( child: Row(
children: [ children: [
Row( Row(
@ -285,7 +298,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
width: 8.sp, width: 8.sp,
), ),
Text( Text(
'${convertToTenThousand(widget.bean.viewTotal)}圈友', '${convertToTenThousand(widget.bean.joinTotal)}圈友',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp), fontSize: 12.sp),
@ -381,7 +394,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
height: 4.sp, height: 4.sp,
), ),
Text( Text(
'${convertToTenThousand(widget.bean.joinTotal)}人看过', '${convertToTenThousand(widget.bean.viewTotal)}人看过',
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: TextStyle( style: TextStyle(
color: Color(0xff03FEFB), color: Color(0xff03FEFB),
@ -465,21 +478,17 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
), ),
), ),
Container( Container(
margin: EdgeInsets.only(top: 24.sp), margin: EdgeInsets.only(top: 24.sp,bottom: 24.sp),
child: Column( child: Container(
children: [ margin: EdgeInsets.only(
Container( top: 12.sp, left: 14.sp, right: 14.sp),
margin: EdgeInsets.only( alignment: Alignment.center,
top: 12.sp, left: 14.sp, right: 14.sp), child: SingleChildScrollView(child: Text(
alignment: Alignment.center, msg,
child: Text( textAlign: TextAlign.center,
msg, style: TextStyle(
textAlign: TextAlign.center, color: Color(0xCCF7FAFA), fontSize: 16.sp),
style: TextStyle( ),),
color: Color(0xCCF7FAFA), fontSize: 16.sp),
),
),
],
), ),
) )
], ],
@ -508,7 +517,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
onTap: () { onTap: () {
pushOtherPeopleHomePage(element.id.toString()); pushOtherPeopleHomePage(element.id.toString());
}, },
child: circleWidget(element.avatar!, width: 24), child: circleWidget(element.avatar!,element.id.toString(), width: 24),
), ),
)); ));
index++; index++;
@ -822,7 +831,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
onTap: () { onTap: () {
pushOtherPeopleHomePage(element.id.toString()); pushOtherPeopleHomePage(element.id.toString());
}, },
child: circleWidget(element.avatar!, width: 24), child: circleWidget(element.avatar!,element.id.toString(), width: 24),
), ),
)); ));
index++; index++;
@ -1082,8 +1091,11 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
)); ));
} }
circleWidget(String url, {double width = 30}) { circleWidget(String url, String userId,{double width = 30}) {
return GestureDetector( return GestureDetector(
onTap: (){
Get.toNamed(AppRoutes.UserInfoActivity, arguments: userId);
},
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
@ -1096,7 +1108,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
url, url,
width: (width - 1).sp, width: (width - 1).sp,
height: (width - 1).sp, height: (width - 1).sp,
fit: BoxFit.fill, fit: BoxFit.cover,
), ),
) )
], ],

View File

@ -8,6 +8,8 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../../util/SharedPreferencesHelper.dart';
class ListLogic extends GetxController { class ListLogic extends GetxController {
int callOutPage = 1; int callOutPage = 1;
@ -77,13 +79,18 @@ class ListLogic extends GetxController {
} }
void pushHomePage(Lists bean,String cicleId) async { void pushHomePage(Lists bean,String cicleId) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
int userId = prefs.getInt("userId")??0; int userId = sharedPreferences.getInt(SharedPreferencesHelper.USERID);
if(bean.user!.id==userId){ if(bean.user!.id==userId){
Get.toNamed(AppRoutes.UserInfoActivity); Get.toNamed(AppRoutes.UserInfoActivity);
}else{ }else{
Get.toNamed(AppRoutes.UserInfoActivity, arguments: bean.user!.id!.toString()); Get.toNamed(AppRoutes.UserInfoActivity, arguments: bean.user!.id!.toString());
} }
});
// if (bean.isQueen) { // if (bean.isQueen) {
// showJoinCiclePiker(cicleId); // showJoinCiclePiker(cicleId);

View File

@ -182,6 +182,8 @@ class FriendslistPage extends StatelessWidget {
return "喜欢我的"; return "喜欢我的";
case "2": case "2":
return "最近访客"; return "最近访客";
case "3":
return "最近来访";
default: default:
return ""; return "";
} }

View File

@ -1,4 +1,5 @@
import 'package:circle_app/app/circle/logic.dart'; import 'package:circle_app/app/circle/logic.dart';
import 'package:circle_app/app/minefragment/logic.dart';
import 'package:circle_app/util/util.dart'; import 'package:circle_app/util/util.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -39,6 +40,10 @@ class HomeLogic extends GetxController {
if (index == 1) { if (index == 1) {
final logic = Get.put(CircleLogic()); final logic = Get.put(CircleLogic());
logic.loadCirclePeopleData(); logic.loadCirclePeopleData();
}else
if(index == 2){
final logic = Get.put(MinefragmentLogic());
logic.getMode();
} }
update(); update();
} }

View File

@ -11,6 +11,7 @@ import '../../../common/config.dart';
import '../../../network/api.dart'; import '../../../network/api.dart';
import '../../../util/device.dart'; import '../../../util/device.dart';
import '../../../util/qiniu.dart'; import '../../../util/qiniu.dart';
import '../../minefragment/logic.dart';
import '../../select_circle/logic.dart'; import '../../select_circle/logic.dart';
import '../../userinfo/logic.dart'; import '../../userinfo/logic.dart';
import 'state.dart'; import 'state.dart';
@ -46,7 +47,7 @@ class Complete_materialLogic extends GetxController {
state.sex = getGenderContent(userInfoBean!.gender); state.sex = getGenderContent(userInfoBean!.gender);
state.genderId = userInfoBean!.gender.toString(); state.genderId = userInfoBean!.gender.toString();
state.age = userInfoBean!.age.toString(); state.age = userInfoBean!.age.toString();
state.brithday = userInfoBean!.age.toString(); state.brithday = userInfoBean!.birthday.toString();
state.role = getRoleContent(userInfoBean!.role); state.role = getRoleContent(userInfoBean!.role);
state.roleId = userInfoBean!.role.toString(); state.roleId = userInfoBean!.role.toString();
state.orientation = getOrientationContent(userInfoBean!.orientation); state.orientation = getOrientationContent(userInfoBean!.orientation);
@ -153,7 +154,7 @@ class Complete_materialLogic extends GetxController {
showToast('请上传头像'); showToast('请上传头像');
return; return;
} }
LatLng location = await getLocation(); // LatLng location = await getLocation();
List<String> interestsList = []; List<String> interestsList = [];
numbers.forEach((element) { numbers.forEach((element) {
interestsList.add(element.id); interestsList.add(element.id);
@ -165,8 +166,8 @@ class Complete_materialLogic extends GetxController {
'role': state.roleId, //Int 'role': state.roleId, //Int
'interests': interestsList, // 'interests': interestsList, //
'orientation': state.orientationId, //Int 'orientation': state.orientationId, //Int
'lat': location.latitude, // 'lat': location.latitude,
'lng': location.longitude, // 'lng': location.longitude,
'nickname': state.textEditingController.text, 'nickname': state.textEditingController.text,
'signature': state.descEditingController.text, 'signature': state.descEditingController.text,
}); });
@ -215,7 +216,7 @@ class Complete_materialLogic extends GetxController {
return; return;
} }
//TODO //TODO
LatLng location = await getLocation(); // LatLng location = await getLocation();
List<String> interestsList = []; List<String> interestsList = [];
numbers.forEach((element) { numbers.forEach((element) {
interestsList.add(element.id); interestsList.add(element.id);
@ -227,14 +228,25 @@ class Complete_materialLogic extends GetxController {
'role': state.roleId, //Int 'role': state.roleId, //Int
'interests': interestsList, // 'interests': interestsList, //
'orientation': state.orientationId, //Int 'orientation': state.orientationId, //Int
'lat': location.latitude, // 'lat': location.latitude,
'lng': location.longitude, // 'lng': location.longitude,
'nickname': state.textEditingController.text, 'nickname': state.textEditingController.text,
'signature': state.descEditingController.text, 'signature': state.descEditingController.text,
}); });
var bean = BaseResponse<String>.fromJson(data, (data) => data); var bean = BaseResponse<String>.fromJson(data, (data) => data);
if (bean.code == 200) { if (bean.code == 200) {
var mineFragment = Get.find<MinefragmentLogic>();
mineFragment.avatar = headUrl;
mineFragment.name = state.textEditingController.text;
mineFragment.gender = int.parse(state.genderId);
mineFragment.role = int.parse(state.roleId);
mineFragment.age = int.parse(state.age);
mineFragment.orientation = int.parse(state.orientationId);
mineFragment.update();
Get.back(); Get.back();
}else{ }else{
showToast(bean.msg); showToast(bean.msg);
} }

View File

@ -11,6 +11,7 @@ import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../../network/api.dart'; import '../../../network/api.dart';
import '../../../util/SharedPreferencesHelper.dart';
import 'state.dart'; import 'state.dart';
class LoginLogic extends GetxController { class LoginLogic extends GetxController {
@ -70,14 +71,18 @@ class LoginLogic extends GetxController {
}); });
var bean = BaseResponse<LoginData>.fromJson(data, (data) => LoginData.fromJson(data)); var bean = BaseResponse<LoginData>.fromJson(data, (data) => LoginData.fromJson(data));
if (bean.code == 200) { if (bean.code == 200) {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setString('Authorization', bean.data!.Authorization.toString()); sharedPreferences.setString(SharedPreferencesHelper.AUTHORIZATION,bean.data!.Authorization.toString());
});
Get.offNamed(AppRoutes.Home); Get.offNamed(AppRoutes.Home);
return; return;
} else if (bean.code == 30002) { } else if (bean.code == 30002) {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setString('Authorization', bean.data!.Authorization.toString()); sharedPreferences.setString(SharedPreferencesHelper.AUTHORIZATION,bean.data!.Authorization.toString());
});
Get.offNamed(AppRoutes.Complete_materialPage); Get.offNamed(AppRoutes.Complete_materialPage);
return; return;
@ -93,7 +98,6 @@ class LoginLogic extends GetxController {
// String msg = jsonData['msg']; // String msg = jsonData['msg'];
// //
// String authorization = jsonData['data']['Authorization']; // String authorization = jsonData['data']['Authorization'];
// SharedPreferences prefs = await SharedPreferences.getInstance();
// prefs.setString('Authorization', authorization); // prefs.setString('Authorization', authorization);
// //
// if (code == 200) { // if (code == 200) {

View File

@ -3,6 +3,7 @@ import 'package:get/get.dart';
import '../../network/api.dart'; import '../../network/api.dart';
import '../../network/dio_manager.dart'; import '../../network/dio_manager.dart';
import '../../router/app_routers.dart'; import '../../router/app_routers.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../../util/util.dart'; import '../../util/util.dart';
import '../userinfo/logic.dart'; import '../userinfo/logic.dart';
import 'state.dart'; import 'state.dart';
@ -17,45 +18,65 @@ class MinefragmentLogic extends GetxController {
var like_me_count = 0; var like_me_count = 0;
var recent_visit_count = 0; var recent_visit_count = 0;
num like_me_count_new = 0; num like_me_count_new = 0;
num recent_visit_count_new = 0; num recent_visit_count_new = 0;
String avatar = "";
String name = "";
int gender = -1;
int role = -1;
int age = -1;
int orientation = -1;
String enterHomeInfoMsg = "进入主页";
@override @override
void onInit() async { void onInit() async {
super.onInit(); super.onInit();
getMode();
}
getMode() async {
var data = await DioManager.instance.get(url: Api.getUserMine); var data = await DioManager.instance.get(url: Api.getUserMine);
var bean = BaseResponse<ResponseBean>.fromJson( var bean = BaseResponse<MineResponseBean>.fromJson(
data, (data) => ResponseBean.fromJson(data)); data, (data) => MineResponseBean.fromJson(data));
if (bean.isSuccess()) { if (bean.isSuccess()) {
SharedPreferences prefs = await SharedPreferences.getInstance(); like_count = bean.data.likeCount ?? 0;
int likeMeCount = prefs.getInt("likeMeCount") ?? 0; like_me_count = bean.data.likeMeCount ?? 0;
int recentVisitCount = prefs.getInt("recentVisitCount") ?? 0; recent_visit_count = bean.data.recentVisitCount ?? 0;
prefs.setString("photo", bean.data.phone); SharedPreferences sharedPreferences =
await SharedPreferences.getInstance();
like_count = bean.data.likeCount??0; int likeMeCount = sharedPreferences.getInt(SharedPreferencesHelper.LIKEMECOUNT)??0;
like_me_count = bean.data.likeMeCount??0; int recentVisitCount = sharedPreferences.getInt(SharedPreferencesHelper.RECENTVISITCOUNT)??0;
recent_visit_count = bean.data.recentVisitCount??0; sharedPreferences.setString(SharedPreferencesHelper.PHOTO, bean.data.phone);
like_me_count_new = likeMeCount - like_me_count;
print("***************");
print("$likeMeCount-$like_me_count=$like_me_count_new");
recent_visit_count_new = recentVisitCount - recent_visit_count;
// like_me_count_new = recentVisitCount.toInt() - bean.data.likeMeCount.toInt(); // like_me_count_new = recentVisitCount.toInt() - bean.data.likeMeCount.toInt();
like_me_count_new = likeMeCount - like_me_count;
print("***************");
print(likeMeCount.toString()+"-"+like_me_count.toString()+"="+like_me_count_new.toString());
recent_visit_count_new = recentVisitCount-recent_visit_count;
userInfoBean = bean.data.user; userInfoBean = bean.data.user;
if (userInfoBean != null) { if (userInfoBean != null) {
avatar = userInfoBean!.avatar;
sharedPreferences.setString(SharedPreferencesHelper.AVATAR, avatar);
name = userInfoBean!.nickname;
sharedPreferences.setString(SharedPreferencesHelper.NAME, name);
gender = userInfoBean!.gender;
role = userInfoBean!.role;
age = userInfoBean!.age;
orientation = userInfoBean!.orientation;
isVip = userInfoBean!.vip; isVip = userInfoBean!.vip;
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('vip', isVip); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setInt('userId', userInfoBean!.id); sharedPreferences.setInt(SharedPreferencesHelper.VIP, isVip);
ageMsg = getAgeCOntent(userInfoBean!.gender, userInfoBean!.age, sharedPreferences.setInt(
userInfoBean!.role, userInfoBean!.orientation); SharedPreferencesHelper.USERID, userInfoBean!.id);
});
ageMsg = getAgeCOntent(gender, age, role, orientation);
} }
update(); update();
@ -122,7 +143,7 @@ class User {
} }
} }
class ResponseBean { class MineResponseBean {
User user; User user;
int likeCount; int likeCount;
int likeMeCount; int likeMeCount;
@ -131,18 +152,17 @@ class ResponseBean {
int? vipExpireDays; int? vipExpireDays;
String phone; String phone;
ResponseBean({ MineResponseBean(
required this.user, {required this.user,
required this.likeCount, required this.likeCount,
required this.likeMeCount, required this.likeMeCount,
required this.recentVisitCount, required this.recentVisitCount,
this.vipExpireDate, this.vipExpireDate,
this.vipExpireDays, this.vipExpireDays,
required this.phone required this.phone});
});
factory ResponseBean.fromJson(Map<String, dynamic> json) { factory MineResponseBean.fromJson(Map<String, dynamic> json) {
return ResponseBean( return MineResponseBean(
user: User.fromJson(json['user']), user: User.fromJson(json['user']),
likeCount: json['like_count'], likeCount: json['like_count'],
phone: json['phone'], phone: json['phone'],

View File

@ -5,6 +5,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../../util/util.dart'; import '../../util/util.dart';
import 'logic.dart'; import 'logic.dart';
@ -37,7 +38,7 @@ class MinefragmentPage extends StatelessWidget {
), ),
child: Padding( child: Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: 20.0 + statusBarHeight, top: 20.0 + statusBarHeight.sp,
left: 11.sp, left: 11.sp,
right: 11.sp, right: 11.sp,
), ),
@ -77,7 +78,7 @@ class MinefragmentPage extends StatelessWidget {
}, },
child: Container( child: Container(
// color: Colors.red, // color: Colors.red,
margin: EdgeInsets.only(top: 18), margin: EdgeInsets.only(top: 18.sp),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -85,10 +86,10 @@ class MinefragmentPage extends StatelessWidget {
children: [ children: [
Image( Image(
image: AssetImage(getHomeImage("mine_setup")), image: AssetImage(getHomeImage("mine_setup")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
SizedBox(width: 10), SizedBox(width: 10.sp),
Text( Text(
"设置", "设置",
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
@ -99,8 +100,8 @@ class MinefragmentPage extends StatelessWidget {
children: [ children: [
Image( Image(
image: AssetImage(getHomeImage("icon_in")), image: AssetImage(getHomeImage("icon_in")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
], ],
) )
@ -118,7 +119,7 @@ class MinefragmentPage extends StatelessWidget {
// controller.state.hearUrl // controller.state.hearUrl
}, },
child: Container( child: Container(
margin: EdgeInsets.only(top: 18), margin: EdgeInsets.only(top: 18.sp),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -126,10 +127,10 @@ class MinefragmentPage extends StatelessWidget {
children: [ children: [
Image( Image(
image: AssetImage(getHomeImage("mine_help")), image: AssetImage(getHomeImage("mine_help")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
SizedBox(width: 10), SizedBox(width: 10.sp),
Text( Text(
"帮助与反馈", "帮助与反馈",
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
@ -140,8 +141,8 @@ class MinefragmentPage extends StatelessWidget {
children: [ children: [
Image( Image(
image: AssetImage(getHomeImage("icon_in")), image: AssetImage(getHomeImage("icon_in")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
], ],
) )
@ -158,7 +159,7 @@ class MinefragmentPage extends StatelessWidget {
Get.toNamed(AppRoutes.MyCircle,arguments: ''); Get.toNamed(AppRoutes.MyCircle,arguments: '');
}, },
child: Container( child: Container(
margin: EdgeInsets.only(top: 18), margin: EdgeInsets.only(top: 18.sp),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -166,10 +167,10 @@ class MinefragmentPage extends StatelessWidget {
children: [ children: [
Image( Image(
image: AssetImage(getHomeImage("mine_circle")), image: AssetImage(getHomeImage("mine_circle")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
SizedBox(width: 10), SizedBox(width: 10.sp),
Text( Text(
"我的圈子", "我的圈子",
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
@ -184,8 +185,8 @@ class MinefragmentPage extends StatelessWidget {
), ),
Image( Image(
image: AssetImage(getHomeImage("icon_in")), image: AssetImage(getHomeImage("icon_in")),
width: 24, width: 24.sp,
height: 24, height: 24.sp,
), ),
], ],
) )
@ -199,15 +200,14 @@ class MinefragmentPage extends StatelessWidget {
return Center( return Center(
child: Container( child: Container(
width: Get.width, width: Get.width,
height: 85, height: 85.sp,
margin: EdgeInsets.only(left: 30, right: 30), margin: EdgeInsets.only(left: 30.sp, right: 30.sp),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
print("我喜欢的");
Get.toNamed(AppRoutes.FriendsActivity, arguments: "0"); Get.toNamed(AppRoutes.FriendsActivity, arguments: "0");
}, },
child: Container( child: Container(
@ -219,7 +219,7 @@ class MinefragmentPage extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
SizedBox(height: 4.sp), SizedBox(height: 4.sp),
Text( Text(
@ -234,7 +234,7 @@ class MinefragmentPage extends StatelessWidget {
], ],
color: Color.fromARGB(255, 247, 250, 250), color: Color.fromARGB(255, 247, 250, 250),
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
], ],
), ),
@ -246,9 +246,9 @@ class MinefragmentPage extends StatelessWidget {
logic.like_me_count_new = 0; logic.like_me_count_new = 0;
logic.update(); logic.update();
if(null!=logic.like_me_count){ if(null!=logic.like_me_count){
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
SharedPreferences prefs = await SharedPreferences.getInstance(); sharedPreferences.setInt(SharedPreferencesHelper.LIKEMECOUNT, logic.like_me_count);
prefs.setInt("likeMeCount", logic.like_me_count); });
} }
Get.toNamed(AppRoutes.FriendsActivity, arguments: "1"); Get.toNamed(AppRoutes.FriendsActivity, arguments: "1");
}, },
@ -265,7 +265,7 @@ class MinefragmentPage extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
), ),
], ],
@ -286,7 +286,7 @@ class MinefragmentPage extends StatelessWidget {
], ],
color: Color.fromARGB(255, 247, 250, 250), color: Color.fromARGB(255, 247, 250, 250),
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
], ],
), ),
@ -306,8 +306,12 @@ class MinefragmentPage extends StatelessWidget {
onTap: () async{ onTap: () async{
logic.recent_visit_count_new = 0; logic.recent_visit_count_new = 0;
if(null!=logic.recent_visit_count){ if(null!=logic.recent_visit_count){
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setInt("recentVisitCount", logic.recent_visit_count); sharedPreferences.setInt(SharedPreferencesHelper.RECENTVISITCOUNT, logic.recent_visit_count);
});
} }
Get.toNamed(AppRoutes.FriendsActivity, arguments: "2"); Get.toNamed(AppRoutes.FriendsActivity, arguments: "2");
@ -326,7 +330,7 @@ class MinefragmentPage extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
), ),
], ],
@ -347,7 +351,7 @@ class MinefragmentPage extends StatelessWidget {
], ],
color: Color.fromARGB(255, 247, 250, 250), color: Color.fromARGB(255, 247, 250, 250),
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold), ),
), ),
], ],
), ),
@ -377,11 +381,32 @@ class MinefragmentPage extends StatelessWidget {
}, },
child: Container( child: Container(
width: Get.width, width: Get.width,
height: 65, height: 65.sp,
child: Row( child: Row(
children: [ children: [
Center( Center(
child: _buildAvatar1(logic), child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 68.sp,
height: 68.sp,
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [Color(0xFFDD3DF4), Color(0xFF30FFD9)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
SizedBox(
width: 65.sp,
height: 65.sp,
child: _buildAvatar1(logic),
)
],
),
), ),
Expanded( Expanded(
child: Container( child: Container(
@ -403,6 +428,8 @@ class MinefragmentPage extends StatelessWidget {
} }
Widget _buildAvatar1(MinefragmentLogic logic) { Widget _buildAvatar1(MinefragmentLogic logic) {
return ClipOval( return ClipOval(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
@ -422,7 +449,8 @@ class MinefragmentPage extends StatelessWidget {
height: 65.sp, height: 65.sp,
): CachedNetworkImage( ): CachedNetworkImage(
fit: BoxFit.cover, fit: BoxFit.cover,
imageUrl: logic.userInfoBean!=null ? logic.userInfoBean!.avatar: "", placeholder: null,
imageUrl: logic.avatar,
width: 65.sp, width: 65.sp,
height: 65.sp, height: 65.sp,
), ),
@ -433,29 +461,30 @@ class MinefragmentPage extends StatelessWidget {
Widget _buildNameRow(MinefragmentLogic logic) { Widget _buildNameRow(MinefragmentLogic logic) {
return Container( return Container(
margin: EdgeInsets.only(top: 6.sp),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
logic.userInfoBean!=null ? logic.userInfoBean!.nickname:"", logic.name,
style: TextStyle( style: TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0), color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 16, fontSize: 16.sp,
), ),
), ),
Row( Row(
children: [ children: [
Text( Text(
"进入主页", logic.enterHomeInfoMsg,
style: TextStyle( style: TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0), color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 16, fontSize: 16.sp,
), ),
), ),
Image( Image(
image: AssetImage(getHomeImage("icon_in")), image: AssetImage(getHomeImage("icon_in")),
width: 44, width: 44.sp,
height: 18, height: 18.sp,
), ),
], ],
), ),
@ -479,21 +508,21 @@ class MinefragmentPage extends StatelessWidget {
end: Alignment.centerRight, end: Alignment.centerRight,
), ),
), ),
padding: EdgeInsets.only(top: 2, bottom: 2, left: 10, right: 10), padding: EdgeInsets.only(top: 2.sp, bottom: 2.sp, left: 10.sp, right: 10.sp),
child: Text( child: Text(
logic.ageMsg, logic.ageMsg,
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 10, fontSize: 10.sp,
), ),
), ),
), ),
SizedBox(width: 6), SizedBox(width: 6.sp),
logic.isVip>0 ? logic.isVip>0 ?
Image( Image(
image: AssetImage(getBaseImage("vip")), image: AssetImage(getBaseImage("vip")),
width: 44, width: 44.sp,
height: 18, height: 18.sp,
):Container(), ):Container(),
], ],
); );

View File

@ -14,16 +14,23 @@ import 'state.dart';
class PhotoinfoLogic extends GetxController { class PhotoinfoLogic extends GetxController {
final PhotoinfoState state = PhotoinfoState(); final PhotoinfoState state = PhotoinfoState();
TextEditingController photoController = TextEditingController();
@override // TextEditingController passwordController = TextEditingController();
void onClose() { TextEditingController newPhotoController = TextEditingController();
timer.cancel(); TextEditingController codeController = TextEditingController();
super.onClose();
}
int countdownSeconds = 60; int countdownSeconds = 60;
bool isCountingDown = false; bool isCountingDown = false;
late Timer timer ; Timer? timer ;
@override
void onClose() {
timer?.cancel();
super.onClose();
}
// @override // @override
@ -36,9 +43,9 @@ class PhotoinfoLogic extends GetxController {
bindingPhoto()async{ bindingPhoto()async{
var data = await DioManager.instance.put(url: Api.bindingPhoto, params: { var data = await DioManager.instance.put(url: Api.bindingPhoto, params: {
"old_phone": state.photoController.text.toString(), "old_phone": photoController.text.toString(),
"new_phone": state.newPhotoController.text.toString(), "new_phone": newPhotoController.text.toString(),
"code": state.codeController.text.toString(), "code": codeController.text.toString(),
}); });
// var activity = Get.find<MinefragmentLogic>(); // var activity = Get.find<MinefragmentLogic>();
// activity.isVip // activity.isVip
@ -46,7 +53,7 @@ class PhotoinfoLogic extends GetxController {
showToast(bean.msg); showToast(bean.msg);
if(bean.isSuccess()){ if(bean.isSuccess()){
final accountLogic = Get.find<AccountLogic>(); final accountLogic = Get.find<AccountLogic>();
accountLogic.photo = state.newPhotoController.text.toString(); accountLogic.photo = newPhotoController.text.toString();
accountLogic.update(); accountLogic.update();
Get.back(); Get.back();
@ -65,22 +72,22 @@ class PhotoinfoLogic extends GetxController {
print(countdownSeconds.toString()); print(countdownSeconds.toString());
} else { } else {
isCountingDown = false; isCountingDown = false;
timer.cancel(); timer?.cancel();
} }
}); });
} }
Future<void> getCode() async { Future<void> getCode() async {
if (state.newPhotoController.text == "" || state.newPhotoController.text .length < 11) { if(!GetUtils.isPhoneNumber(newPhotoController.text)){
showToast("新手机号输入有误"); showToast("新手机号输入有误");
return; return;
} }
var data = await DioManager.instance.post(url: Api.sendCode, params: {"phone": state.newPhotoController.text}); var data = await DioManager.instance.post(url: Api.sendCode, params: {"phone": newPhotoController.text});
var bean = BaseResponse<Data>.fromJson(data, (data) => Data.fromJson(data)); var bean = BaseResponse<Data>.fromJson(data, (data) => Data.fromJson(data));
showToast(bean.msg); showToast(bean.msg);
if(kDebugMode){ if(kDebugMode){
if(bean.code==200){ if(bean.code==200){
state.codeController.text = bean.data!.code.toString(); codeController.text = bean.data!.code.toString();
startCountdown(); startCountdown();
update(); update();
} }

View File

@ -1,11 +1,10 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
class PhotoinfoState { class PhotoinfoState {
TextEditingController photoController = TextEditingController();
// TextEditingController passwordController = TextEditingController();
TextEditingController newPhotoController = TextEditingController();
TextEditingController codeController = TextEditingController();
PhotoinfoState() { PhotoinfoState() {
///Initialize variables ///Initialize variables
} }
} }

View File

@ -13,8 +13,8 @@ import 'logic.dart';
class PhotoinfoPage extends StatelessWidget { class PhotoinfoPage extends StatelessWidget {
PhotoinfoPage({Key? key}) : super(key: key); PhotoinfoPage({Key? key}) : super(key: key);
//
final logic = Get.lazyPut(() => PhotoinfoLogic()); // final logic = Get.lazyPut(() => PhotoinfoLogic());
// @override // @override
// void dispose() { // void dispose() {
// _timer?.cancel(); // _timer?.cancel();
@ -36,7 +36,7 @@ class PhotoinfoPage extends StatelessWidget {
), ),
child: Scaffold( child: Scaffold(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
appBar: MyAppBar( appBar: const MyAppBar(
centerTitle: '换绑手机号', centerTitle: '换绑手机号',
), ),
body: Scaffold( body: Scaffold(
@ -75,16 +75,19 @@ class PhotoinfoPage extends StatelessWidget {
height: 32.sp, height: 32.sp,
alignment: Alignment.center, alignment: Alignment.center,
child: TextField( child: TextField(
controller: logic.state.photoController, controller: logic.photoController,
textAlignVertical: TextAlignVertical.center, textAlignVertical: TextAlignVertical.center,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
FilteringTextInputFormatter.deny( FilteringTextInputFormatter.deny(
RegExp('[^0-9]')), RegExp('[^0-9]')),
], ],
maxLines: 1,
maxLength: 11,
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入已绑定手机号", hintText: "请输入已绑定手机号",
counterText:"",
hintStyle: TextStyle( hintStyle: TextStyle(
color: Colors.grey.shade300, color: Colors.grey.shade300,
fontSize: 14.0.sp, fontSize: 14.0.sp,
@ -175,7 +178,7 @@ class PhotoinfoPage extends StatelessWidget {
height: 32.sp, height: 32.sp,
alignment: Alignment.center, alignment: Alignment.center,
child: TextField( child: TextField(
controller: logic.state.newPhotoController, controller: logic.newPhotoController,
textAlignVertical: TextAlignVertical.center, textAlignVertical: TextAlignVertical.center,
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
inputFormatters: [ inputFormatters: [
@ -183,10 +186,14 @@ class PhotoinfoPage extends StatelessWidget {
FilteringTextInputFormatter.deny( FilteringTextInputFormatter.deny(
RegExp('[^0-9]')), RegExp('[^0-9]')),
], ],
maxLines: 1,
maxLength: 11,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入新手机号", hintText: "请输入新手机号",
counterText: '',
hintStyle: TextStyle( hintStyle: TextStyle(
color: Colors.grey.shade300, color: Colors.grey.shade300,
fontSize: 14.0.sp, fontSize: 14.0.sp,
), ),
border: InputBorder.none, border: InputBorder.none,
@ -231,7 +238,7 @@ class PhotoinfoPage extends StatelessWidget {
height: 32.sp, height: 32.sp,
alignment: Alignment.center, alignment: Alignment.center,
child: TextField( child: TextField(
controller: logic.state.codeController, controller: logic.codeController,
textAlignVertical: TextAlignVertical.center, textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入验证码", hintText: "请输入验证码",
@ -301,10 +308,10 @@ class PhotoinfoPage extends StatelessWidget {
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
String photo = logic.state.photoController.text; String photo = logic.photoController.text;
// String password = logic.state.passwordController.text; // String password = logic.state.passwordController.text;
String newphoto = logic.state.newPhotoController.text; String newphoto = logic.newPhotoController.text;
String code = logic.state.codeController.text; String code = logic.codeController.text;
if (photo == "" || photo.length < 11) { if (photo == "" || photo.length < 11) {
showToast("已绑定的手机号输入有误"); showToast("已绑定的手机号输入有误");
return; return;

View File

@ -1,6 +1,7 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../router/app_routers.dart'; import '../../router/app_routers.dart';
import '../../util/SharedPreferencesHelper.dart';
import 'state.dart'; import 'state.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -22,14 +23,17 @@ class SplashLogic extends GetxController {
await DioManager.instance.put(url: Api.refreshToken,params:{}); await DioManager.instance.put(url: Api.refreshToken,params:{});
var bean = BaseResponse<LoginData>.fromJson(data, (data) => LoginData.fromJson(data)); var bean = BaseResponse<LoginData>.fromJson(data, (data) => LoginData.fromJson(data));
if (bean.code == 200) { if (bean.code == 200) {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setString('Authorization', bean.data!.Authorization.toString()); sharedPreferences.setString(SharedPreferencesHelper.AUTHORIZATION,bean.data!.Authorization.toString());
});
Get.offNamed(AppRoutes.Home); Get.offNamed(AppRoutes.Home);
return; return;
} else if (bean.code == 30002) { } else if (bean.code == 30002) {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.setString('Authorization', bean.data!.Authorization.toString()); sharedPreferences.setString(SharedPreferencesHelper.AUTHORIZATION,bean.data!.Authorization.toString());
});
Get.offNamed(AppRoutes.Complete_materialPage); Get.offNamed(AppRoutes.Complete_materialPage);
return; return;
} }

View File

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -9,9 +7,9 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../../common/config.dart'; import '../../common/config.dart';
import '../../network/api.dart'; import '../../network/api.dart';
import '../../network/dio_manager.dart'; import '../../network/dio_manager.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../../util/qiniu.dart'; import '../../util/qiniu.dart';
import '../../util/util.dart'; import '../../util/util.dart';
import '../login/complete_material/logic.dart';
import 'state.dart'; import 'state.dart';
class UserinfoLogic extends GetxController { class UserinfoLogic extends GetxController {
@ -31,28 +29,36 @@ class UserinfoLogic extends GetxController {
bool isShowAlbum = true; bool isShowAlbum = true;
bool isLike = false; bool isLike = false;
final startTime = DateTime.now();
@override @override
void onInit() async { void onInit() async {
super.onInit(); super.onInit();
SharedPreferences prefs = await SharedPreferences.getInstance();
if(prefs.getInt('userId')!=0&&prefs.getInt('userId').toString()==userId){ if (userId != '') {
userId = ''; SharedPreferences sharedPreferences =
await SharedPreferences.getInstance();
if (sharedPreferences.getInt(SharedPreferencesHelper.USERID) != 0 &&
sharedPreferences.getInt(SharedPreferencesHelper.USERID).toString() ==
userId) {
userId = '';
}
} }
state.imaglist.clear();
if (userId == '') { if (userId == '') {
isMe = true; isMe = true;
var data = await DioManager.instance.get(url: Api.getUserInfo); var data = await DioManager.instance.get(url: Api.getUserInfo);
var bean = BaseResponse<ResponseBean>.fromJson( var bean = BaseResponse<ResponseBean>.fromJson(
data, (data) => ResponseBean.fromJson(data)); data, (data) => ResponseBean.fromJson(data));
if (bean.isSuccess()) { if (bean.isSuccess()) {
isLikeFoMsg = isLikeFoMsg =
"${bean.data.imageUrgeCount}位圈友感兴趣,其中${bean.data.likeMeCount}位已催您更新"; "${bean.data.imageUrgeCount}位圈友感兴趣,其中${bean.data.likeMeCount}位已催您更新";
userInfoBean = bean.data.user; userInfoBean = bean.data.user;
isVip = userInfoBean!.vip; isVip = userInfoBean!.vip;
//访线
onLineCity = userInfoBean!.isOnline == true ? "在线" : "离线"; userInfoBean!.isOnline = true;
onLineCity = userInfoBean!.isOnline ? "在线" : "离线";
isOnline = userInfoBean!.isOnline; isOnline = userInfoBean!.isOnline;
if (userInfoBean!.city != null) { if (userInfoBean!.city != null) {
onLineCity = "$onLineCity·${userInfoBean!.city}"; onLineCity = "$onLineCity·${userInfoBean!.city}";
@ -73,6 +79,8 @@ class UserinfoLogic extends GetxController {
state.imaglist.add(element); state.imaglist.add(element);
}); });
} }
} else { } else {
isMe = false; isMe = false;
var data = await DioManager.instance var data = await DioManager.instance
@ -81,7 +89,8 @@ class UserinfoLogic extends GetxController {
data, (data) => ResponseBean.fromJson(data)); data, (data) => ResponseBean.fromJson(data));
if (bean.isSuccess()) { if (bean.isSuccess()) {
isLike = bean.data.is_follow; isLike = bean.data.is_follow;
isLikeFoMsg = "${bean.data.imageUrgeCount}位圈友感兴趣,其中${bean.data.likeMeCount}位已催您更新"; isLikeFoMsg =
"${bean.data.imageUrgeCount}位圈友感兴趣,其中${bean.data.likeMeCount}位已催您更新";
userInfoBean = bean.data!.user; userInfoBean = bean.data!.user;
isVip = userInfoBean!.vip; isVip = userInfoBean!.vip;
@ -97,7 +106,7 @@ class UserinfoLogic extends GetxController {
} }
var myAlbumData = await DioManager.instance var myAlbumData = await DioManager.instance
.get(url: Api.getTaAlbum + userId + "/albums"); .get(url: "${Api.getTaAlbum + userId}/albums");
var myAlbumBean = BaseResponse<AlbumResponseBean>.fromJson(myAlbumData, var myAlbumBean = BaseResponse<AlbumResponseBean>.fromJson(myAlbumData,
(myAlbumData) => AlbumResponseBean.fromJson(myAlbumData)); (myAlbumData) => AlbumResponseBean.fromJson(myAlbumData));
if (myAlbumBean.isSuccess()) { if (myAlbumBean.isSuccess()) {
@ -108,16 +117,17 @@ class UserinfoLogic extends GetxController {
} }
var urgedata = await DioManager.instance var urgedata = await DioManager.instance
.get(url: Api.getUrgeStatus + userId + "/urge/album/status"); .get(url: "${Api.getUrgeStatus + userId}/urge/album/status");
var urgeBean = BaseResponse<UrgentStatus>.fromJson( var urgeBean = BaseResponse<UrgentStatus>.fromJson(
urgedata, (urgedata) => UrgentStatus.fromJson(urgedata)); urgedata, (urgedata) => UrgentStatus.fromJson(urgedata));
//if(urgedata.isSuccess()){ //if(urgedata.isSuccess()){
isUrgeStatus = urgeBean.data.isUrgent; isUrgeStatus = urgeBean.data.isUrgent;
//} //}
} }
update(); update();
var data = var data =
await DioManager.instance.get(url: Api.getqiniuToken, params: {}); await DioManager.instance.get(url: Api.getqiniuToken, params: {});
var bean = BaseResponse<QnTokenData>.fromJson( var bean = BaseResponse<QnTokenData>.fromJson(
@ -140,36 +150,38 @@ class UserinfoLogic extends GetxController {
delAlbumImage(int index) async { delAlbumImage(int index) async {
var data = await DioManager.instance var data = await DioManager.instance
.get(url: Api.deleteAlbum + state.imaglist[index].id.toString()); .delete(url: Api.deleteAlbum + state.imaglist[index].id.toString());
var bean = BaseResponse<String>.fromJson(data, (data) => data); var bean = BaseResponse<String>.fromJson(data, (data) => data);
if (bean.code == 200) { if (bean.code == 200) {
state.imaglist.removeAt(index); state.imaglist.removeAt(index);
Navigator.pop(Get.context!); // Navigator.pop(Get.context!);
update(); update();
} }
} }
setLike() async { setLike() async {
var data = await DioManager.instance var data = await DioManager.instance.post(
.post(url: "${Api.setLike + userId}/follow", params: { url: "${Api.setLike + userId}/follow",
'status': isLike?"0":"1" params: {'status': isLike ? "0" : "1"});
}); var bean = BaseResponse<dynamic>.fromJson(
var bean = BaseResponse<dynamic>.fromJson(data, (jsonData) => jsonData,); data,
if(bean.isSuccess()){ (jsonData) => jsonData,
);
if (bean.isSuccess()) {
isLike = !isLike; isLike = !isLike;
update(); update();
} }
showToast(bean.msg); showToast(bean.msg);
} }
setBlock() async { setBlock() async {
var data = await DioManager.instance var data = await DioManager.instance
.post(url: "${Api.setBlock + userId}/block", params: { .post(url: "${Api.setBlock + userId}/block", params: {'status': "1"});
'status': "1" var bean = BaseResponse<dynamic>.fromJson(
}); data,
var bean = BaseResponse<dynamic>.fromJson(data, (jsonData) => jsonData,); (jsonData) => jsonData,
if(bean.isSuccess()){ );
if (bean.isSuccess()) {
Navigator.pop(Get.context!); Navigator.pop(Get.context!);
update(); update();
} }
@ -294,12 +306,11 @@ class ResponseBean {
int imageUrgeCount; int imageUrgeCount;
bool is_follow; bool is_follow;
ResponseBean({ ResponseBean(
required this.user, {required this.user,
required this.likeMeCount, required this.likeMeCount,
required this.imageUrgeCount, required this.imageUrgeCount,
required this.is_follow required this.is_follow});
});
factory ResponseBean.fromJson(Map<String, dynamic> json) { factory ResponseBean.fromJson(Map<String, dynamic> json) {
return ResponseBean( return ResponseBean(

View File

@ -572,6 +572,7 @@ class _MyTabbedScreenState extends State<UserinfoPage>
}, },
child: CachedNetworkImage( child: CachedNetworkImage(
fit: BoxFit.cover, fit: BoxFit.cover,
placeholder: null,
imageUrl: controller.userInfoBean != null imageUrl: controller.userInfoBean != null
? controller.userInfoBean!.avatar ? controller.userInfoBean!.avatar
: "", : "",

View File

@ -207,6 +207,18 @@ class DioManager {
pushLoginPage(); pushLoginPage();
} }
return responseMap; return responseMap;
// switch(responseMap["code"]){
// case 200:
// case 30503:
// return responseMap;
// case 5003:
// pushLoginPage();
// break;
//
// default:
// return {'code': responseMap["code"], 'msg': responseMap["msg"]};
// }
return responseMap;
} on DioException catch (e) { } on DioException catch (e) {
// // DioError是指返回值不为200的情况 // // DioError是指返回值不为200的情况
// logger.shout('DioError报错${e.type}:${e.error.toString()}'); // logger.shout('DioError报错${e.type}:${e.error.toString()}');
@ -280,7 +292,9 @@ class BaseResponse<T> {
} else { } else {
throw Exception('未提供 fromJsonData 函数来解析数据。'); throw Exception('未提供 fromJsonData 函数来解析数据。');
} }
} else { } else if (dataJson is List) {
data = fromJsonData(dataJson);
}else {
throw Exception('无效的数据格式。期望是 String 或 Map<String, dynamic> 类型。'); throw Exception('无效的数据格式。期望是 String 或 Map<String, dynamic> 类型。');
} }
} }

View File

@ -0,0 +1,66 @@
import 'package:shared_preferences/shared_preferences.dart';
class SharedPreferencesHelper {
static const VIP = 'vip';
static const USERID = 'userId';
static const LIKEMECOUNT = 'likeMeCount';
static const RECENTVISITCOUNT = 'recentVisitCount';
static const PHOTO = 'photo';
static const AUTHORIZATION = 'Authorization';
static const AVATAR = 'avatar';
static const NAME = 'name';
static SharedPreferencesHelper? _instance;
static SharedPreferences? _preferences;
SharedPreferencesHelper._();
static Future<SharedPreferencesHelper> getInstance() async {
if (_instance == null) {
_instance = SharedPreferencesHelper._();
await _instance!._initPreferences();
}
return _instance!;
}
Future<void> _initPreferences() async {
_preferences = await SharedPreferences.getInstance();
}
SharedPreferences? get preferences {
return _preferences;
}
setString(String key, String value) async {
final prefs = preferences;
prefs?.setString(key, value) ?? "";
}
setInt(String key, int value) async {
final prefs = preferences;
prefs?.setInt(key, value) ?? 0;
}
int getInt(String key) {
final prefs = preferences;
return prefs?.getInt(key) ?? 0;
}
String getString(String key) {
final prefs = preferences;
return prefs?.getString(key) ?? '';
}
bool? getBool(String key) {
final prefs = preferences;
return prefs?.getBool(key);
}
void clear() {
final prefs = preferences;
prefs?.clear();
}
}

View File

@ -4,6 +4,9 @@ import 'package:device_info/device_info.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'SharedPreferencesHelper.dart';
// //
Future<String> getDeviceId() async { Future<String> getDeviceId() async {
String deviceId = ""; String deviceId = "";
@ -24,7 +27,6 @@ Future<String> getDeviceId() async {
return deviceId; return deviceId;
} }
Future<String> getVersion() async { Future<String> getVersion() async {
String version = ""; String version = "";
final info = await PackageInfo.fromPlatform(); final info = await PackageInfo.fromPlatform();
@ -38,12 +40,14 @@ Future<String> getVersionName() async {
versionName = info.version; versionName = info.version;
return versionName; return versionName;
} }
Future<String> getVersionCode() async { Future<String> getVersionCode() async {
String versionCode = ""; String versionCode = "";
final info = await PackageInfo.fromPlatform(); final info = await PackageInfo.fromPlatform();
versionCode = info.buildNumber; versionCode = info.buildNumber;
return versionCode; return versionCode;
} }
//imei //imei
Future<String> getImei() async { Future<String> getImei() async {
String imei = ""; String imei = "";
@ -59,6 +63,7 @@ Future<String> getImei() async {
} }
return imei; return imei;
} }
// //
Future<String> getBrand() async { Future<String> getBrand() async {
String brand = ''; String brand = '';
@ -74,7 +79,8 @@ Future<String> getBrand() async {
} }
Future<LatLng> getLocation() async { Future<LatLng> getLocation() async {
LatLng latLng = LatLng(latitude: 0.0, longitude: 0.0);; LatLng latLng = LatLng(latitude: 0.0, longitude: 0.0);
;
try { try {
LocationPermission permission = await Geolocator.requestPermission(); LocationPermission permission = await Geolocator.requestPermission();
if (permission == LocationPermission.whileInUse || if (permission == LocationPermission.whileInUse ||
@ -84,7 +90,8 @@ Future<LatLng> getLocation() async {
); );
print('Latitude: ${position.latitude}'); print('Latitude: ${position.latitude}');
print('Longitude: ${position.longitude}'); print('Longitude: ${position.longitude}');
latLng= LatLng(latitude: position.latitude, longitude: position.longitude); latLng =
LatLng(latitude: position.latitude, longitude: position.longitude);
} else { } else {
print('Location permission denied'); print('Location permission denied');
} }
@ -102,6 +109,8 @@ class LatLng {
} }
Future<String> getAuthorization() async { Future<String> getAuthorization() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); String token ="";
return prefs.getString("Authorization") ?? ""; SharedPreferences sharedPreferences =await SharedPreferences.getInstance();
token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??"";
return token;
} }

View File

@ -13,6 +13,8 @@ import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:video_compress/video_compress.dart'; import 'package:video_compress/video_compress.dart';
import 'SharedPreferencesHelper.dart';
class Util { class Util {
} }
@ -130,8 +132,11 @@ String convertToTenThousand(int number) {
} }
} }
pushLoginPage() async{ pushLoginPage() async{
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferencesHelper.getInstance().then((sharedPreferences) {
prefs.clear(); sharedPreferences.clear();
});
Get.offAllNamed(AppRoutes.Login); Get.offAllNamed(AppRoutes.Login);
} }
String filterSensitiveWords(String input, List<String> sensitiveWords) { String filterSensitiveWords(String input, List<String> sensitiveWords) {