flutter - 如何在flutter_swiper中动态禁用滑动按钮?
问题描述
我正在使用flutter_swiper来滑动图像。如您所见,我有两个滑动器,我想动态禁用这两个滑动器箭头,我该怎么做?
我不能从一开始就禁用,因为我想在满足某些条件时禁用它
这是一些示例代码:-
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,
),
),
),
],
),
))));
}
}
现在我想在特定事件触发的功能的帮助下禁用这些箭头
解决方案
我通过 在布尔标志的帮助下禁用iconPrevious:
并在运行时找到了解决方案。iconNext:
如果标志为假,则启用按钮,如果标志为真,则禁用。
例子:
var disable=false;
这是一个标志,如果值为 false,它将允许显示滑动按钮
现在,在控制器中设置标志
control: new SwiperControl(
iconPrevious: disable?null:Icons.arrow_back_ios,
iconNext:disable?null:Icons.arrow_forward_ios,
),
使用按钮中的设置状态更改标志。
next(){
setState(() {
disable=true;
});
}
推荐阅读
- css - 悬停时如何停止当前正在运行的动画并更改样式
- c++ - 保持坐标排序
- javascript - 如何从 WhatsApp 位置共享中检索位置坐标?
- c# - 如何在 C# 中修复 HTML 行
- laravel - 如何在laravel中的00:00:00停止时间减法
- c++ - 当从相同的 c/c++ 源代码编译时,为什么“.exe”比“.out”大得多?
- sql-server - asp.net核心中身份ID的格式和长度是什么?
- mongodb - dockerizing mongodb 时 influxdb:root 拥有的 mongodb 数据目录
- python - 从 FileNotFoundError 中引发 ValueError,然后执行其他操作
- c - Collect2.exe 错误:ld 返回 5 退出状态