内部存储 封装 改了一下小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:shared_preferences/shared_preferences.dart';
import '../../util/SharedPreferencesHelper.dart';
import 'state.dart';
class AccountLogic extends GetxController {
@ -10,9 +11,15 @@ class AccountLogic extends GetxController {
void onInit() async{
super.onInit();
SharedPreferences prefs = await SharedPreferences.getInstance();
photo = prefs.getString("photo")??"";
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
// 使 SharedPreferences
photo = sharedPreferences.getString(SharedPreferencesHelper.PHOTO);
print(photo.toString());
update();
});
}
}

View File

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

View File

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

View File

@ -1,4 +1,3 @@
import 'dart:ffi';
import 'package:cached_network_image/cached_network_image.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:get/get.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 {
// Get.lazyPut(() => ListLogic());
@ -141,14 +140,19 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
}
void pushHomePage(Lists bean, String cicleId) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
int userId = prefs.getInt("userId") ?? 0;
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
int userId = sharedPreferences.getInt(SharedPreferencesHelper.USERID);
if (bean.user!.id == userId) {
Get.toNamed(AppRoutes.UserInfoActivity);
} else {
Get.toNamed(AppRoutes.UserInfoActivity,
arguments: bean.user!.id!.toString());
}
});
// if (bean.isQueen) {
// showJoinCiclePiker(cicleId);
@ -166,9 +170,10 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
@override
Widget build(BuildContext context) {
TextSpan descSpan;
// widget.bean.intro = widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro;
TextSpan span;
if (widget.bean.intro.length > 60) {
String truncatedText = widget.bean.intro.substring(0, 60);
if (widget.bean.intro.length > 20) {
String truncatedText = widget.bean.intro.substring(0, 60)+"...";
descSpan = TextSpan(
text: truncatedText,
style: TextStyle(color: Colors.white, fontSize: 10.sp),
@ -192,9 +197,12 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
List<Widget> widgets = [];
int i = 0;
urlList.forEach((element) {
if(widgets.length>2){
return;
}
widgets.add(Positioned(
left: 15.sp * i,
child: circleWidget(element.avatar),
child: circleWidget(element.avatar,element.id.toString()),
));
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(
children: [
Row(
@ -285,7 +298,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
width: 8.sp,
),
Text(
'${convertToTenThousand(widget.bean.viewTotal)}圈友',
'${convertToTenThousand(widget.bean.joinTotal)}圈友',
style: TextStyle(
color: Colors.white,
fontSize: 12.sp),
@ -381,7 +394,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
height: 4.sp,
),
Text(
'${convertToTenThousand(widget.bean.joinTotal)}人看过',
'${convertToTenThousand(widget.bean.viewTotal)}人看过',
textAlign: TextAlign.left,
style: TextStyle(
color: Color(0xff03FEFB),
@ -465,21 +478,17 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
),
),
Container(
margin: EdgeInsets.only(top: 24.sp),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 24.sp,bottom: 24.sp),
child: Container(
margin: EdgeInsets.only(
top: 12.sp, left: 14.sp, right: 14.sp),
alignment: Alignment.center,
child: Text(
child: SingleChildScrollView(child: Text(
msg,
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xCCF7FAFA), fontSize: 16.sp),
),
),
],
),),
),
)
],
@ -508,7 +517,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
onTap: () {
pushOtherPeopleHomePage(element.id.toString());
},
child: circleWidget(element.avatar!, width: 24),
child: circleWidget(element.avatar!,element.id.toString(), width: 24),
),
));
index++;
@ -822,7 +831,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
onTap: () {
pushOtherPeopleHomePage(element.id.toString());
},
child: circleWidget(element.avatar!, width: 24),
child: circleWidget(element.avatar!,element.id.toString(), width: 24),
),
));
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(
onTap: (){
Get.toNamed(AppRoutes.UserInfoActivity, arguments: userId);
},
child: Stack(
alignment: Alignment.center,
children: [
@ -1096,7 +1108,7 @@ class _InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClie
url,
width: (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:shared_preferences/shared_preferences.dart';
import '../../../util/SharedPreferencesHelper.dart';
class ListLogic extends GetxController {
int callOutPage = 1;
@ -77,13 +79,18 @@ class ListLogic extends GetxController {
}
void pushHomePage(Lists bean,String cicleId) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
int userId = prefs.getInt("userId")??0;
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
int userId = sharedPreferences.getInt(SharedPreferencesHelper.USERID);
if(bean.user!.id==userId){
Get.toNamed(AppRoutes.UserInfoActivity);
}else{
Get.toNamed(AppRoutes.UserInfoActivity, arguments: bean.user!.id!.toString());
}
});
// if (bean.isQueen) {
// showJoinCiclePiker(cicleId);

View File

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

View File

@ -1,4 +1,5 @@
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:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@ -39,6 +40,10 @@ class HomeLogic extends GetxController {
if (index == 1) {
final logic = Get.put(CircleLogic());
logic.loadCirclePeopleData();
}else
if(index == 2){
final logic = Get.put(MinefragmentLogic());
logic.getMode();
}
update();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -207,6 +207,18 @@ class DioManager {
pushLoginPage();
}
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) {
// // DioError是指返回值不为200的情况
// logger.shout('DioError报错${e.type}:${e.error.toString()}');
@ -280,6 +292,8 @@ class BaseResponse<T> {
} else {
throw Exception('未提供 fromJsonData 函数来解析数据。');
}
} else if (dataJson is List) {
data = fromJsonData(dataJson);
}else {
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:shared_preferences/shared_preferences.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'SharedPreferencesHelper.dart';
//
Future<String> getDeviceId() async {
String deviceId = "";
@ -24,7 +27,6 @@ Future<String> getDeviceId() async {
return deviceId;
}
Future<String> getVersion() async {
String version = "";
final info = await PackageInfo.fromPlatform();
@ -38,12 +40,14 @@ Future<String> getVersionName() async {
versionName = info.version;
return versionName;
}
Future<String> getVersionCode() async {
String versionCode = "";
final info = await PackageInfo.fromPlatform();
versionCode = info.buildNumber;
return versionCode;
}
//imei
Future<String> getImei() async {
String imei = "";
@ -59,6 +63,7 @@ Future<String> getImei() async {
}
return imei;
}
//
Future<String> getBrand() async {
String brand = '';
@ -74,7 +79,8 @@ Future<String> getBrand() async {
}
Future<LatLng> getLocation() async {
LatLng latLng = LatLng(latitude: 0.0, longitude: 0.0);;
LatLng latLng = LatLng(latitude: 0.0, longitude: 0.0);
;
try {
LocationPermission permission = await Geolocator.requestPermission();
if (permission == LocationPermission.whileInUse ||
@ -84,7 +90,8 @@ Future<LatLng> getLocation() async {
);
print('Latitude: ${position.latitude}');
print('Longitude: ${position.longitude}');
latLng= LatLng(latitude: position.latitude, longitude: position.longitude);
latLng =
LatLng(latitude: position.latitude, longitude: position.longitude);
} else {
print('Location permission denied');
}
@ -102,6 +109,8 @@ class LatLng {
}
Future<String> getAuthorization() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString("Authorization") ?? "";
String token ="";
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:video_compress/video_compress.dart';
import 'SharedPreferencesHelper.dart';
class Util {
}
@ -130,8 +132,11 @@ String convertToTenThousand(int number) {
}
}
pushLoginPage() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.clear();
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
sharedPreferences.clear();
});
Get.offAllNamed(AppRoutes.Login);
}
String filterSensitiveWords(String input, List<String> sensitiveWords) {