From d4e4e155a67550e820942d02a1ece57525c79b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=93=88=E5=93=88=E5=93=88?= Date: Thu, 25 Aug 2022 15:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=84=89=E9=8C=A2=E5=8C=85=EF=BC=8CUI?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mine/mine_wallet_page.dart | 213 +++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 53 deletions(-) diff --git a/lib/mine/mine_wallet_page.dart b/lib/mine/mine_wallet_page.dart index aecccfbe..1adc710a 100644 --- a/lib/mine/mine_wallet_page.dart +++ b/lib/mine/mine_wallet_page.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:dio/dio.dart'; +import 'package:flare_flutter/base/actor_ellipse.dart'; import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; @@ -49,8 +50,8 @@ class _MineWalletPage extends State { UserInfo.fromJson(jsonDecode(sharedPreferences.getString('user'))); mBalance = double.tryParse(userInfo.money); mgreenMoney = double.tryParse(userInfo.greenMoney); - tBalance = double.tryParse(userInfo.balance ?? "0"); activityMoney = double.tryParse(userInfo.activityMoney); + tBalance = mBalance - (mgreenMoney ?? 0) - (activityMoney ?? 0); if (mounted) setState(() {}); String token = sharedPreferences.getString("token"); apiService = ApiService(Dio(), context: context, token: token); @@ -67,10 +68,10 @@ class _MineWalletPage extends State { await apiService.queryInfo().catchError((onError) {}); if (baseData != null && baseData.isSuccess) { userInfo = baseData.data; - mBalance = double.tryParse(userInfo.money); mgreenMoney = double.tryParse(userInfo.greenMoney); - tBalance = double.tryParse(userInfo.balance ?? "0"); activityMoney = double.tryParse(userInfo.activityMoney); + mBalance = double.tryParse(userInfo.money); + tBalance = mBalance - (mgreenMoney ?? 0) - (activityMoney ?? 0); if (mounted) setState(() {}); } } @@ -211,19 +212,46 @@ class _MineWalletPage extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - userBill.name, - style: TextStyle( - color: Colors.black, - fontSize: 12.sp, - ), - ), - Text( - calculateBalance(userBill, 0), - style: TextStyle( - color: Color(0xFF20662A), - fontWeight: FontWeight.bold, - fontSize: 12.sp, + Expanded( + flex: 7, + child: Text( + userBill.name, + style: TextStyle( + color: Colors.black, + 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( + e, + style: TextStyle( + color: Color(0xFF20662A), + fontWeight: FontWeight.bold, + fontSize: 12.sp, + ), + ), + ) + .toList(), ), ), ], @@ -231,19 +259,48 @@ class _MineWalletPage extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - userBill.createTime, - style: TextStyle( - color: Color(0xFF727272), - fontSize: 10.sp, + Expanded( + flex: 7, + child: Text( + userBill.createTime, + style: TextStyle( + color: Color(0xFF727272), + fontSize: 10.sp, + ), ), ), - Text( - calculateBalance(userBill, 1), - style: TextStyle( - color: Color(0xFF20662A), - fontWeight: FontWeight.bold, - fontSize: 12.sp, + 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( + color: Color(0xFF20662A), + fontWeight: FontWeight.bold, + fontSize: 12.sp, + ), + ), + ) + : Text( + e, + style: TextStyle( + color: Color(0xFF20662A), + fontWeight: FontWeight.bold, + fontSize: 12.sp, + ), + ), + ) + .toList(), ), ), ], @@ -253,22 +310,52 @@ class _MineWalletPage extends State { ), Row( children: [ - Expanded(flex: 1, child: Text( - S.of(context).pingtaizongyue(userBill.balance, - userBill.surplusActivityMoney, userBill.surplusGreenMoney), - style: TextStyle( - color: Color(0xFF727272), - fontSize: 10.sp, - ), - )), - Text( - calculateBalance(userBill, 2), - style: TextStyle( - color: Color(0xFF20662A), - fontWeight: FontWeight.bold, - fontSize: 12.sp, + Expanded( + flex: 7, + child: Text( + S.of(context).pingtaizongyue( + userBill.balance, + userBill.surplusActivityMoney, + userBill.surplusGreenMoney), + style: TextStyle( + color: Color(0xFF727272), + fontSize: 10.sp, + ), + )), + if (calculateBalance(userBill, 2).isNotEmpty) + 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( + color: Color(0xFF20662A), + fontWeight: FontWeight.bold, + 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 { return zero == 0; } - calculateBalance(UserBill userBill, int index) { + List 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 activityMoney = userBill.activityMoney; - String number = userBill.number; - double balance = double.tryParse(number ?? "0"); + double money = double.tryParse(greenMoney ?? "0"); double activity = double.tryParse(activityMoney ?? "0"); if (index == 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) { - 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) { if (activity > 0) { - return S.of(context).huodongyue_("${userBill.pm == 0 ? '-' : '+'}$activity"); + return [ + S.of(context).huodongyue, + "${userBill.pm == 0 ? '-' : '+'}$activity" + ]; } if (money > 0) { - return S.of(context).yue__("${userBill.pm == 0 ? '-' : '+'}${(balance - money)}"); + return [ + S.of(context).yue, + "${userBill.pm == 0 ? '-' : '+'}${(balance - money)}" + ]; } else { - return ""; + return []; } } else { 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 { - return ""; + return []; } } }