我已经创建了PageViewBuilder来显示我的列表项...当我到达列表的最后一项时...我想显示一个隐藏的小部件如何实现?
这是当我到达列表的最后一个项目时要显示的小部件
Expanded(
flex: 3,
child: Container(
height: 40,width: 40,
color: Colors.black87,
child: MaterialButton(onPressed: (){},child: Text('Done',style: TextStyle(
fontSize: 20,fontWeight: FontWeight.w500,color: Colors.white
),),)),
下面是我完整代码
class _getPlanExDetails2ScreenState extends State<getPlanExDetails2Screen> {
@override
Widget build(BuildContext context) {
return BlocConsumer<LifeStyleCubit,LifeStates>(
listener: (context,state)
{},
builder: (context,state)
{
var cubit = LifeStyleCubit.get(context);
return Scaffold(
appBar: AppBar(
elevation: 0,
title: Text('Exercise'),
),
body: PageView.builder(
itemBuilder: (BuildContext context,index) => letsTest(cubit.PlanDaysExList[index],context,index),
itemCount: cubit.PlanDaysExList.length,
scrollDirection: Axis.horizontal,
controller: widget.pageController,
),
bottomNavigationBar: Padding(
padding: const EdgeInsets.only(bottom:20,right: 75,left: 75 ),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
height: 40,width: 40,
child: MaterialButton(onPressed: ()
{
widget.pageController.previousPage(duration:Duration(milliseconds: 500),
curve: Curves.easeInOut);
},child: Icon(IconBroken.Arrow___Left_2
,color: Colors.white,),)),
),
Expanded(
flex: 3,
child: Container(
height: 40,width: 40,
color: Colors.black87,
child: MaterialButton(onPressed: (){},child: Text('Done',style: TextStyle(
fontSize: 20,fontWeight: FontWeight.w500,color: Colors.white
),),)), // i need to show this widget when i reach to the last index of the list
),
Expanded(
child: Container(
height: 40,width: 20,
child: MaterialButton(onPressed: ()
{
widget.pageController.nextPage(duration:Duration(milliseconds: 500),
curve: Curves.easeInOut);
},child: Icon(IconBroken.Arrow___Right_2
,color: Colors.white,),)),
),
],
),
),
);
},
);
}
我尝试用Visiblity小部件 Package 它并使用setState,但失败了
1条答案
按热度按时间rkue9o1l1#
我认为你应该设置一个if语句关于最后一个问题,并把**
visibile: true;
。虽然您不希望它对其他问题可见,但 * 您应该将visible:false;*在展开的小工具内。
我希望它能帮助你的问题。有美好的编码时间!