tabview 中显示错误的数据。
在我的应用程序中,我的所有选项卡都是动态创建的,当我第一次点击“VEG PIZZA”然后立即更改我的“NEW LAUNCH”选项卡时,我的“veg pizza”数据显示在“New launch”上时,我遇到了这个问题标签视图。
我不知道如何解决它。
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../Utils/GlobalColor/global_color.dart';
import '../../../Utils/GlobalTextStyles/global_text_styles.dart';
import '../BlocPages/CubitPage/MenuListCubit/menu_list_cubit.dart';
import '../BlocPages/CubitPage/MenuListCubit/menu_list_state.dart';
import '../SkeletonsPage/skeleton.dart';
import '../Utils/ConstantsPages/constants.dart';
import '../Utils/ConstantsPages/toast_page.dart';
import 'Components/pizza_card.dart';
class VegPizzaPage extends StatefulWidget {
final menuCategoryData;
const VegPizzaPage({Key? key, this.menuCategoryData}) : super(key: key);
@override
State<VegPizzaPage> createState() => _VegPizzaPageState();
}
class _VegPizzaPageState extends State<VegPizzaPage> {
bool isVeg = false;
bool isNonVeg = false;
bool showBtn = false;
@override
void initState() {
print("menuCategoryData:: ${widget.menuCategoryData}");
super.initState();
setState(() {
myCategoryId = widget.menuCategoryData["Id"];
});
}
@override
void didChangeDependencies() {
print("didChangeDependencies");
BlocProvider.of<MenuListCubit>(context)
.menuList(widget.menuCategoryData["Id"], outletId);
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return BlocConsumer<MenuListCubit, MenuListState>(
listener: (context, menuListState) {
if (menuListState is MenuListCodeSentState) {
// myPizza.clear();
// myPizza.addAll(menuListState.menuListData);
}
if (menuListState is MenuListErrorState) {
showToastWithBlackColor(menuListState.error.toString());
}
},
builder: (context, menuListState) {
if (menuListState is MenuListLoadingState) {
return SingleChildScrollView(
child: Column(
children: [
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
SliderSkeleton(
aspectRatio: 16 / 7.5,
),
],
),
);
} else if (menuListState is MenuListCodeSentState) {
return Container(
color: MyColor.bgLightColor,
child: Stack(
children: [
widget.menuCategoryData["Id"] == 106 ||
widget.menuCategoryData["Id"] ==
105
? Container(
alignment: Alignment.center,
height: 52,
child: Center(
child: Padding(
padding: EdgeInsets.only(
top: 0, left: 20, right: 20, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
InkWell(
onTap: () {
setState(() {
isVeg = !isVeg;
isNonVeg =
isNonVeg ? !isNonVeg : isNonVeg;
print("isNonVeg" + isNonVeg.toString());
print("isVeg" + isVeg.toString());
// myPizza.clear();
for (int i = 0;
i < menuListState.menuListData.length;
i++) {
if (isVeg) {
if (menuListState.menuListData[i]
["IsVeg"] ==
true) {
// myPizza.add(
// menuListState.menuListData[i]);
}
print("here");
} else if (isNonVeg) {
if (menuListState.menuListData[i]
["IsVeg"] ==
false) {
// myPizza.add(
// menuListState.menuListData[i]);
}
print("here1");
} else {
print("here2");
// myPizza.add(
// menuListState.menuListData[i]);
}
}
// log(myPizza.length.toString());
});
},
child: Row(
children: [
Container(
alignment: Alignment.center,
height: 16,
width: 16,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(1.5),
border: Border.all(
width: 2,
color: MyColor.greenColor),
// color:MyColor.blueColor
),
child: Padding(
padding: const EdgeInsets.all(0.0),
child: isVeg
? Icon(
Icons.check_outlined,
size: 12.0,
color: MyColor.greenColor,
)
: Icon(
Icons.check_outlined,
size: 12.0,
color: MyColor.bgLightColor,
),
),
),
SizedBox(width: 6),
Text(
'VEG ONLY',
style: textStyleWith10500(
MyColor.blackColor),
),
],
),
),
SizedBox(
width: 18,
),
InkWell(
onTap: () {
setState(() {
isNonVeg = !isNonVeg;
isVeg = isVeg ? !isVeg : isVeg;
print("isNonVeg" + isNonVeg.toString());
print("isVeg" + isVeg.toString());
// myPizza.clear();
for (int i = 0;
i < menuListState.menuListData.length;
i++) {
if (isVeg) {
if (menuListState.menuListData[i]
["IsVeg"] ==
true) {
// myPizza.add(
// menuListState.menuListData[i]);
}
print("here..");
} else if (isNonVeg) {
if (menuListState.menuListData[i]
["IsVeg"] ==
false) {
// myPizza.add(
// menuListState.menuListData[i]);
}
print("here1..");
} else {
print("here2..");
// myPizza.add(
// menuListState.menuListData[i]);
}
}
// log(myPizza.length.toString());
});
},
child: Row(
children: [
Container(
alignment: Alignment.center,
height: 16,
width: 16,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(1.5),
border: Border.all(
width: 2,
color: MyColor.primaryRedColor),
// color:MyColor.blueColor
),
child: Padding(
padding: const EdgeInsets.all(0.0),
child: isNonVeg
? Icon(
Icons.check_outlined,
size: 12.0,
color:
MyColor.primaryRedColor,
)
: Icon(
Icons.check_outlined,
size: 12.0,
color: MyColor.bgLightColor,
),
),
),
SizedBox(
width: 6,
),
Text(
'NON-VEG ONLY',
style: textStyleWith10500(
MyColor.blackColor),
),
],
),
),
],
),
),
),
) : Container(),
cards(menuListState.menuListData),
],
),
);
}
if (menuListState is MenuListErrorState) {
return Center(
child: Text("${menuListState.error}"),
);
}
return Container();
},
);
}
}
extension WidgetExtension on _VegPizzaPageState {
cards(myPizza) {
return myPizza.length == 0
? Center(
child: Text("No records found!"),
)
: Padding(
padding: EdgeInsets.only(top: widget.menuCategoryData["Id"] == 106 ||
widget.menuCategoryData["Id"] ==
105 ? 52 : 0.0),
child: ListView.builder(
physics: ScrollPhysics(),
padding: EdgeInsets.only(top: widget.menuCategoryData["Id"] == 106 ||
widget.menuCategoryData["Id"] ==
105 ? 11 : 20.0, bottom: 20),
shrinkWrap: true,
itemCount: myPizza.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(
top: index == 0 ? 0 : 12,
),
child: PizzaCard(
myPizza: myPizza[index],
),
);
}),
);
}
}