Browse Source

回鄉錢包,UI修改

dart3_last
哈哈哈 2 years ago
parent
commit
d4e4e155a6
  1. 157
      lib/mine/mine_wallet_page.dart

157
lib/mine/mine_wallet_page.dart

@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flare_flutter/base/actor_ellipse.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
@ -49,8 +50,8 @@ class _MineWalletPage extends State<MineWalletPage> {
UserInfo.fromJson(jsonDecode(sharedPreferences.getString('user'))); UserInfo.fromJson(jsonDecode(sharedPreferences.getString('user')));
mBalance = double.tryParse(userInfo.money); mBalance = double.tryParse(userInfo.money);
mgreenMoney = double.tryParse(userInfo.greenMoney); mgreenMoney = double.tryParse(userInfo.greenMoney);
tBalance = double.tryParse(userInfo.balance ?? "0");
activityMoney = double.tryParse(userInfo.activityMoney); activityMoney = double.tryParse(userInfo.activityMoney);
tBalance = mBalance - (mgreenMoney ?? 0) - (activityMoney ?? 0);
if (mounted) setState(() {}); if (mounted) setState(() {});
String token = sharedPreferences.getString("token"); String token = sharedPreferences.getString("token");
apiService = ApiService(Dio(), context: context, token: token); apiService = ApiService(Dio(), context: context, token: token);
@ -67,10 +68,10 @@ class _MineWalletPage extends State<MineWalletPage> {
await apiService.queryInfo().catchError((onError) {}); await apiService.queryInfo().catchError((onError) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
userInfo = baseData.data; userInfo = baseData.data;
mBalance = double.tryParse(userInfo.money);
mgreenMoney = double.tryParse(userInfo.greenMoney); mgreenMoney = double.tryParse(userInfo.greenMoney);
tBalance = double.tryParse(userInfo.balance ?? "0");
activityMoney = double.tryParse(userInfo.activityMoney); activityMoney = double.tryParse(userInfo.activityMoney);
mBalance = double.tryParse(userInfo.money);
tBalance = mBalance - (mgreenMoney ?? 0) - (activityMoney ?? 0);
if (mounted) setState(() {}); if (mounted) setState(() {});
} }
} }
@ -211,41 +212,97 @@ class _MineWalletPage extends State<MineWalletPage> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Expanded(
flex: 7,
child: Text(
userBill.name, userBill.name,
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 12.sp, fontSize: 12.sp,
), ),
)),
Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 0)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
), ),
Text( )
calculateBalance(userBill, 0), : Text(
e,
style: TextStyle( style: TextStyle(
color: Color(0xFF20662A), color: Color(0xFF20662A),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 12.sp, fontSize: 12.sp,
), ),
), ),
)
.toList(),
),
),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Expanded(
flex: 7,
child: Text(
userBill.createTime, userBill.createTime,
style: TextStyle( style: TextStyle(
color: Color(0xFF727272), color: Color(0xFF727272),
fontSize: 10.sp, fontSize: 10.sp,
), ),
), ),
Text( ),
calculateBalance(userBill, 1), if (calculateBalance(userBill, 1).isNotEmpty)
Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 1)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle( style: TextStyle(
color: Color(0xFF20662A), color: Color(0xFF20662A),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 12.sp, fontSize: 12.sp,
), ),
), ),
)
: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
.toList(),
),
),
], ],
), ),
SizedBox( SizedBox(
@ -253,22 +310,52 @@ class _MineWalletPage extends State<MineWalletPage> {
), ),
Row( Row(
children: [ children: [
Expanded(flex: 1, child: Text( Expanded(
S.of(context).pingtaizongyue(userBill.balance, flex: 7,
userBill.surplusActivityMoney, userBill.surplusGreenMoney), child: Text(
S.of(context).pingtaizongyue(
userBill.balance,
userBill.surplusActivityMoney,
userBill.surplusGreenMoney),
style: TextStyle( style: TextStyle(
color: Color(0xFF727272), color: Color(0xFF727272),
fontSize: 10.sp, fontSize: 10.sp,
), ),
)), )),
Text( if (calculateBalance(userBill, 2).isNotEmpty)
calculateBalance(userBill, 2), Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 2)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle( style: TextStyle(
color: Color(0xFF20662A), color: Color(0xFF20662A),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 12.sp, fontSize: 12.sp,
), ),
), ),
)
: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
.toList(),
),
),
], ],
), ),
], ],
@ -282,35 +369,55 @@ class _MineWalletPage extends State<MineWalletPage> {
return zero == 0; return zero == 0;
} }
calculateBalance(UserBill userBill, int index) { List<String> calculateBalance(UserBill userBill, int index) {
double tbalance = double.tryParse(userBill.balance ?? "0");///
String surplusGreenMoney = userBill.surplusGreenMoney;
String surplusActivityMoney = userBill.surplusActivityMoney;
double surplusMoney = double.tryParse(surplusGreenMoney ?? "0");
double surplusActivity = double.tryParse(surplusActivityMoney ?? "0");
double balance = tbalance - (surplusMoney ?? 0) - (surplusActivity ?? 0);
String greenMoney = userBill.greenMoney; String greenMoney = userBill.greenMoney;
String activityMoney = userBill.activityMoney; String activityMoney = userBill.activityMoney;
String number = userBill.number;
double balance = double.tryParse(number ?? "0");
double money = double.tryParse(greenMoney ?? "0"); double money = double.tryParse(greenMoney ?? "0");
double activity = double.tryParse(activityMoney ?? "0"); double activity = double.tryParse(activityMoney ?? "0");
if (index == 0) { if (index == 0) {
if (money > 0) { if (money > 0) {
return S.of(context).lvbiyue_("${userBill.pm == 0 ? '-' : '+'}$money"); return [S.of(context).lvbiyue, "${userBill.pm == 0 ? '-' : '+'}$money"];
} }
if (activity > 0) { if (activity > 0) {
return S.of(context).huodongyue_("${userBill.pm == 0 ? '-' : '+'}$activity"); return [
S.of(context).huodongyue,
"${userBill.pm == 0 ? '-' : '+'}$activity"
];
}
if (balance > 0) {
return [S.of(context).yue, "${userBill.pm == 0 ? '-' : '+'}$balance"];
} }
return S.of(context).yue__("${userBill.pm == 0 ? '-' : '+'}$balance");
} else if (index == 1) { } else if (index == 1) {
if (activity > 0) { if (activity > 0) {
return S.of(context).huodongyue_("${userBill.pm == 0 ? '-' : '+'}$activity"); return [
S.of(context).huodongyue,
"${userBill.pm == 0 ? '-' : '+'}$activity"
];
} }
if (money > 0) { if (money > 0) {
return S.of(context).yue__("${userBill.pm == 0 ? '-' : '+'}${(balance - money)}"); return [
S.of(context).yue,
"${userBill.pm == 0 ? '-' : '+'}${(balance - money)}"
];
} else { } else {
return ""; return [];
} }
} else { } else {
if (activity > 0 && money > 0) { if (activity > 0 && money > 0) {
return S.of(context).yue__("${userBill.pm == 0 ? '-' : '+'}${(balance - money - activity)}"); return [
S.of(context).yue,
"${userBill.pm == 0 ? '-' : '+'}${(balance - money - activity)}"
];
} else { } else {
return ""; return [];
} }
} }
} }

Loading…
Cancel
Save