Flutter - MatrixGestureDetector 不适用于 flutter_swiper
Flutter - MatrixGestureDetector is not working with flutter_swiper
我正在使用 flutter_swiper
从图像列表中滑动图像。我想使用 MatrixGestureDetector
移动包含图像的滑动条并对其执行放大缩小。当我将 swiper 布局设置为 Default 时,它工作得很好,但是当我将其更改为 Custom 或任何其他布局时,它停止工作。谁能告诉我应该是什么问题???
这是我的代码
Stack(
children: <Widget>[
/// EYES
new Align(
child: MatrixGestureDetector(
onMatrixUpdate: (m, tm, sm, rm) {
setState(() {
notifier1.value =m;
});
},
shouldRotate: false,
// shouldScale: true,
// shouldTranslate: false,
child: AnimatedBuilder(
animation: notifier1,
builder: (ctx, child) {
return Transform(
transform: notifier1.value,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment(0, -0.1),
child: Tooltip(
message: "Eyes Selected",
child: Container(
width: ew,
height: eh,
//color: Colors.purple,
child: new SizedBox(
child: Swiper(
onTap: (index){
itemNo = 1;
}
,
itemBuilder:
(BuildContext context,
int index) {
return Image.asset(
eImage[index],
);
},
itemCount: eImage.length,
itemWidth: 300,
itemHeight: 600,
//control: new SwiperControl(),
layout: SwiperLayout.DEFAULT,
customLayoutOption:
CustomLayoutOption(
startIndex: -1,
stateCount: 3)
.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,
),
),
),
),
],
),
);
},
),
),
),
],
),
我得到了解决方案。我使用自定义布局只是为了让起始索引动态化,但后来我发现我也可以在默认布局中做到这一点。 Swiper 自定义布局有问题,所以我在 git 存储库中提出了这个问题。
解决方法:-
为索引使用变量:
var pos=0
//你想要的任何索引
之后在刷卡项目生成器中传递相同的索引并在运行时更新它
Swiper(
onTap: (index){
itemNo = 1;
}
,
itemBuilder:
(BuildContext context,
pos) {
return Image.asset(
eImage[this.pos],
);
},
itemCount: eImage.length,
itemWidth: 300,
itemHeight: 600,
index: pos,
onIndexChanged: (int a)
{
pos=a; //updating new position
},
layout: SwiperLayout.DEFAULT,
),
我正在使用 flutter_swiper
从图像列表中滑动图像。我想使用 MatrixGestureDetector
移动包含图像的滑动条并对其执行放大缩小。当我将 swiper 布局设置为 Default 时,它工作得很好,但是当我将其更改为 Custom 或任何其他布局时,它停止工作。谁能告诉我应该是什么问题???
这是我的代码
Stack(
children: <Widget>[
/// EYES
new Align(
child: MatrixGestureDetector(
onMatrixUpdate: (m, tm, sm, rm) {
setState(() {
notifier1.value =m;
});
},
shouldRotate: false,
// shouldScale: true,
// shouldTranslate: false,
child: AnimatedBuilder(
animation: notifier1,
builder: (ctx, child) {
return Transform(
transform: notifier1.value,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment(0, -0.1),
child: Tooltip(
message: "Eyes Selected",
child: Container(
width: ew,
height: eh,
//color: Colors.purple,
child: new SizedBox(
child: Swiper(
onTap: (index){
itemNo = 1;
}
,
itemBuilder:
(BuildContext context,
int index) {
return Image.asset(
eImage[index],
);
},
itemCount: eImage.length,
itemWidth: 300,
itemHeight: 600,
//control: new SwiperControl(),
layout: SwiperLayout.DEFAULT,
customLayoutOption:
CustomLayoutOption(
startIndex: -1,
stateCount: 3)
.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,
),
),
),
),
],
),
);
},
),
),
),
],
),
我得到了解决方案。我使用自定义布局只是为了让起始索引动态化,但后来我发现我也可以在默认布局中做到这一点。 Swiper 自定义布局有问题,所以我在 git 存储库中提出了这个问题。
解决方法:-
为索引使用变量:
var pos=0
//你想要的任何索引
之后在刷卡项目生成器中传递相同的索引并在运行时更新它
Swiper(
onTap: (index){
itemNo = 1;
}
,
itemBuilder:
(BuildContext context,
pos) {
return Image.asset(
eImage[this.pos],
);
},
itemCount: eImage.length,
itemWidth: 300,
itemHeight: 600,
index: pos,
onIndexChanged: (int a)
{
pos=a; //updating new position
},
layout: SwiperLayout.DEFAULT,
),