修复 活动投票百分比显示不正确的问题

修复 活动投票 总数为0时显示溢出的问题
hmxc
张萌 4 years ago
parent 7ee0ed656d
commit ba6e3e51ff

@ -16,6 +16,7 @@ import 'package:akuCommunity/widget/bee_divider.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/buttons/bee_single_check.dart'; import 'package:akuCommunity/widget/buttons/bee_single_check.dart';
import 'package:akuCommunity/widget/buttons/bottom_button.dart'; import 'package:akuCommunity/widget/buttons/bottom_button.dart';
import 'package:velocity_x/velocity_x.dart';
class VotingDetailPage extends StatefulWidget { class VotingDetailPage extends StatefulWidget {
final int id; final int id;
@ -33,8 +34,8 @@ class _VotingDetailPageState extends State<VotingDetailPage> {
// List<int> _select = []; // List<int> _select = [];
int _selectId; int _selectId;
bool _hasVoted = false; bool _hasVoted = false;
bool get isVoted { bool get finishVoted {
if ((_model.status == 4) || _hasVoted) { if ((_model.status == 4) || _hasVoted || (_model.status == 3)) {
return true; return true;
} }
return false; return false;
@ -76,16 +77,24 @@ class _VotingDetailPageState extends State<VotingDetailPage> {
); );
} }
double _getPercent(num numerator, num denominator) {
if (denominator == 0) {
return 0;
} else {
return (numerator / denominator) * 100;
}
}
Widget _buildVoteCard(AppVoteCandidateVos model) { Widget _buildVoteCard(AppVoteCandidateVos model) {
double _percent = (model.total.toDouble()) / (_model.totals.toDouble()); double _percent = _getPercent(model.total, _model.totals);
return Container( return Container(
padding: EdgeInsets.symmetric(vertical: 40.w), padding: EdgeInsets.symmetric(vertical: 40.w),
constraints: BoxConstraints(maxHeight: 230.w), // constraints: BoxConstraints(maxHeight: 230.w),
child: Row( child: Row(
children: [ children: [
Container( Container(
alignment: Alignment.center, alignment: Alignment.center,
width: 88.w, width: 58.w,
height: 150.w, height: 150.w,
// //
// child: BeeCheckBox( // child: BeeCheckBox(
@ -104,7 +113,7 @@ class _VotingDetailPageState extends State<VotingDetailPage> {
// //
// //
// //
child: _model.status == 3 || _model.status == 1 child: finishVoted
? _unCheck() ? _unCheck()
: GestureDetector( : GestureDetector(
onTap: () { onTap: () {
@ -139,21 +148,22 @@ class _VotingDetailPageState extends State<VotingDetailPage> {
// 10.w.heightBox, // 10.w.heightBox,
model.name.text.black.size(32.sp).make(), model.name.text.black.size(32.sp).make(),
33.w.heightBox, 33.w.heightBox,
isVoted && _model.status != 3 finishVoted
? Row( ? Row(
children: [ children: [
SizedBox( SizedBox(
width: 280.w, width: 290.w,
child: LinearProgressIndicator( child: LinearProgressIndicator(
value: _percent, value: _percent,
), ),
), ),
8.w.widthBox, 8.w.widthBox,
'$_percent%' '${_percent.toStringAsFixed(2)}%'
.text .text
.color(ktextSubColor) .color(ktextSubColor)
.size(24.sp) .size(24.sp)
.make(), .make()
.expand(),
], ],
) )
: SizedBox() : SizedBox()

@ -238,7 +238,8 @@ class _LifePayPageState extends State<LifePayPage> {
controller: _controller, controller: _controller,
extraParams: {'estateId': appProvider.selectedHouse.estateId}, extraParams: {'estateId': appProvider.selectedHouse.estateId},
convert: (model) { convert: (model) {
_selectPay = List.generate(model.tableList.length, _selectPay = List.generate(
(_selectPay.length ?? 0) + model.tableList.length,
(index) => SelectPay(payCount: 0, payTotal: 0.0)); (index) => SelectPay(payCount: 0, payTotal: 0.0));
return model.tableList return model.tableList
.map((e) => LifePayModel.fromJson(e)) .map((e) => LifePayModel.fromJson(e))

@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LifePayRecordPage extends StatefulWidget { class LifePayRecordPage extends StatefulWidget {
LifePayRecordPage({Key key}) : super(key: key); LifePayRecordPage({Key key}) : super(key: key);
@ -80,7 +81,7 @@ class _LifePayRecordPageState extends State<LifePayRecordPage> {
.bold .bold
.make(), .make(),
Spacer(), Spacer(),
'人才智慧社区 ${model.roomName}' '${S.of(context).tempPlotName} ${model.roomName}'
.text .text
.size(24.sp) .size(24.sp)
.color(Color(0xFF999999)) .color(Color(0xFF999999))

Loading…
Cancel
Save