update radio box logical

hmxc
张萌 4 years ago
parent 49f9d8a8fe
commit 8dee43f2b7

@ -37,20 +37,19 @@ class SelectList {
class _LifePayPageState extends State<LifePayPage> { class _LifePayPageState extends State<LifePayPage> {
EasyRefreshController _controller; EasyRefreshController _controller;
List<SelectList> selectItems = []; // List<SelectList> selectItems = [];
List<int> _selectYears = []; List<int> _selectYears = [];
List<LifePayModel> _models; List<LifePayModel> _models = [];
bool get isAllSelect => _models.length == _selectYears.length;
int _getLength(LifePayModel model) { // int _getLength(LifePayModel model) {
int count = 0; // int count = 0;
model.dailyPaymentTypeVos.forEach((element) { // model.dailyPaymentTypeVos.forEach((element) {
element.detailedVoList.forEach((element) { // element.detailedVoList.forEach((element) {
count++; // count++;
}); // });
}); // });
return count; // return count;
} // }
@override @override
void initState() { void initState() {
@ -125,29 +124,35 @@ class _LifePayPageState extends State<LifePayPage> {
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (selectItems[index].selected.length == // if (selectItems[index].selected.length ==
_getLength(model)) { // _getLength(model)) {
selectItems[index].value = false; // selectItems[index].value = false;
selectItems[index].selected.clear(); // selectItems[index].selected.clear();
// _selectYears.remove(index);
// } else {
// selectItems[index].value = true;
// _selectYears.add(index);
// for (var i = 0; i < model.dailyPaymentTypeVos.length; i++) {
// for (var j = 0;
// i <
// model
// .dailyPaymentTypeVos[i].detailedVoList.length;
// i++) {
// String id = model.dailyPaymentTypeVos[i].id.toString() +
// model.dailyPaymentTypeVos[i].detailedVoList[j]
// .groupId
// .toString();
// if (!selectItems[index].selected.contains(id)) {
// selectItems[index].selected.add(id);
// }
// }
// }
// }
// setState(() {});
if (_selectYears.contains(index)) {
_selectYears.remove(index); _selectYears.remove(index);
} else { } else {
selectItems[index].value = true;
_selectYears.add(index); _selectYears.add(index);
for (var i = 0; i < model.dailyPaymentTypeVos.length; i++) {
for (var j = 0;
i <
model
.dailyPaymentTypeVos[i].detailedVoList.length;
i++) {
String id = model.dailyPaymentTypeVos[i].id.toString() +
model.dailyPaymentTypeVos[i].detailedVoList[j]
.groupId
.toString();
if (!selectItems[index].selected.contains(id)) {
selectItems[index].selected.add(id);
}
}
}
} }
setState(() {}); setState(() {});
}, },
@ -220,7 +225,7 @@ class _LifePayPageState extends State<LifePayPage> {
onTap: () { onTap: () {
LifePayDetailPage( LifePayDetailPage(
model: _models[index], model: _models[index],
selectItems: selectItems[index].selected, // selectItems: selectItems[index].selected,
).to(); ).to();
}, },
child: Container( child: Container(
@ -313,7 +318,7 @@ class _LifePayPageState extends State<LifePayPage> {
// ), // ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (isAllSelect) { if (_models.length == _selectYears.length) {
_selectYears.clear(); _selectYears.clear();
} else { } else {
for (var i = 0; i < _models.length; i++) { for (var i = 0; i < _models.length; i++) {
@ -329,13 +334,17 @@ class _LifePayPageState extends State<LifePayPage> {
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
width: 1.w, width: 1.w,
color: isAllSelect ? kPrimaryColor : kDarkSubColor), color: _models.length == _selectYears.length
color: isAllSelect ? kPrimaryColor : Colors.transparent, ? kPrimaryColor
: kDarkSubColor),
color: _models.length == _selectYears.length
? kPrimaryColor
: Colors.transparent,
borderRadius: BorderRadius.circular(20.w)), borderRadius: BorderRadius.circular(20.w)),
curve: Curves.easeInOutCubic, curve: Curves.easeInOutCubic,
width: 40.w, width: 40.w,
height: 40.w, height: 40.w,
child: isAllSelect child: _models.length == _selectYears.length
? Icon( ? Icon(
CupertinoIcons.check_mark, CupertinoIcons.check_mark,
size: 25.w, size: 25.w,

@ -1,10 +1,8 @@
import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/model/manager/life_pay_model.dart'; import 'package:akuCommunity/model/manager/life_pay_model.dart';
import 'package:akuCommunity/pages/life_pay/life_pay_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/bee_parse.dart'; import 'package:akuCommunity/utils/bee_parse.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/buttons/bee_check_box.dart';
import 'package:akuCommunity/widget/buttons/bee_check_radio.dart'; import 'package:akuCommunity/widget/buttons/bee_check_radio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -14,11 +12,9 @@ import 'package:provider/provider.dart';
class LifePayDetailPage extends StatefulWidget { class LifePayDetailPage extends StatefulWidget {
final LifePayModel model; final LifePayModel model;
final List<String> selectItems;
LifePayDetailPage({ LifePayDetailPage({
Key key, Key key,
this.model, this.model,
this.selectItems,
}) : super(key: key); }) : super(key: key);
@override @override
@ -26,6 +22,7 @@ class LifePayDetailPage extends StatefulWidget {
} }
class _LifePayDetailPageState extends State<LifePayDetailPage> { class _LifePayDetailPageState extends State<LifePayDetailPage> {
List<String> _selectItems=[];
int get listLength { int get listLength {
int count = 0; int count = 0;
widget.model.dailyPaymentTypeVos.forEach((element) { widget.model.dailyPaymentTypeVos.forEach((element) {
@ -37,7 +34,7 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
} }
bool get isAllSelect { bool get isAllSelect {
return listLength == widget.selectItems.length; return listLength == _selectItems.length;
} }
Widget _buildTile(int groupId, int id, int years, int price) { Widget _buildTile(int groupId, int id, int years, int price) {
@ -46,17 +43,17 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
String item = id.toString() + groupId.toString(); String item = id.toString() + groupId.toString();
if (widget.selectItems.contains(item)) { if (_selectItems.contains(item)) {
widget.selectItems.remove(item); _selectItems.remove(item);
} else { } else {
widget.selectItems.add(item); _selectItems.add(item);
} }
setState(() {}); setState(() {});
}, },
child: BeeCheckRadio( child: BeeCheckRadio(
value: id.toString() + groupId.toString(), value: id.toString() + groupId.toString(),
groupValue: widget.selectItems)), groupValue: _selectItems)),
24.w.widthBox, 24.w.widthBox,
groupId == 1 groupId == 1
? '$years上半年'.text.black.size(28.sp).make() ? '$years上半年'.text.black.size(28.sp).make()
@ -120,7 +117,7 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (isAllSelect) { if (isAllSelect) {
widget.selectItems.clear(); _selectItems.clear();
} else { } else {
for (var i = 0; for (var i = 0;
i < widget.model.dailyPaymentTypeVos.length; i < widget.model.dailyPaymentTypeVos.length;
@ -135,8 +132,8 @@ class _LifePayDetailPageState extends State<LifePayDetailPage> {
widget.model.dailyPaymentTypeVos[i] widget.model.dailyPaymentTypeVos[i]
.detailedVoList[j].groupId .detailedVoList[j].groupId
.toString(); .toString();
if (!widget.selectItems.contains(id)) { if (!_selectItems.contains(id)) {
widget.selectItems.add(id); _selectItems.add(id);
} }
} }
} }

Loading…
Cancel
Save