gpt4 book ai didi

flutter - 如何在flutter_swiper中动态禁用滑动按钮?

转载 作者:行者123 更新时间:2023-12-03 04:42:14 24 4
gpt4 key购买 nike

我正在使用flutter_swiper滑动图像。我有两个滑动器,如您所见,我想动态禁用这两个滑动器箭头,我该怎么做?
enter image description here
我无法从开始禁用,因为我想在满足某些条件时禁用它
这是一些示例代码:

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {


var eImage = [
"img/eyes/1.png",
"img/eyes/2.png",
"img/eyes/3.png",
];

double height = 200;
int itemNo;
double eh = 200;
double ew = 200;
double nh = 100;
double nw = 300;
double lh = 100;
double lw = 100;

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("img/wal.jpg"),
fit: BoxFit.fill,
),
),
child: Container(
child: Stack(

children: <Widget>[
Align(
alignment: Alignment(0, -0.6),
child: Container(
width: ew,
height: eh,
//color: Colors.purple,
child: new SizedBox(
child: Swiper(
itemBuilder:
(BuildContext context, int index) {
return Image.asset(
eImage[index],
);
},
itemCount: eImage.length,
itemWidth: 200,
itemHeight: 200,
control: new SwiperControl(),
layout: SwiperLayout.DEFAULT,
customLayoutOption: CustomLayoutOption(
startIndex: 1, stateCount: 3) ///<--- here i am trying to start from 1st index
.addRotate([
0 / 180,
0.0,
0 / 180
]).addTranslate([
Offset(-400.0, 0.0),
Offset(0.0, 0.0),
Offset(370, -40.0),
]),
),
height: 200,
width: 350,
),
),
),
],
),
))));
}
}

现在我想借助将在特定事件下触发的功能来禁用那些箭头

最佳答案

我已经找到了解决方案,方法是在运行时借助 bool(boolean) 标志禁用iconPrevious:iconNext:。如果标志为假,则启用按钮;如果标志为真,则禁用按钮。
例:

var disable=false;
这是一个标志,如果值为false,将允许显示滑动按钮
现在,在 Controller 中设置标志
control: new SwiperControl(
iconPrevious: disable?null:Icons.arrow_back_ios,
iconNext:disable?null:Icons.arrow_forward_ios,
),

使用按钮中的设置状态更改标志。
 next(){
setState(() {
disable=true;
});
}

关于flutter - 如何在flutter_swiper中动态禁用滑动按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63000628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com