gpt4 book ai didi

flutter - 如何实现索引堆栈之间的幻灯片过渡?

转载 作者:行者123 更新时间:2023-12-03 04:01:09 25 4
gpt4 key购买 nike

我正在尝试通过滑动过渡从堆栈平滑过渡到另一个。我将索引设置为计数器,每当我按下按钮时,它就会递增并移至下一个堆栈。有没有一种方法可以在索引堆栈中的每个堆栈之间创建幻灯片过渡。

int _counter = 0;

void _incrementCounter() {
setState(() {

_counter++;
}
);
}



child: IndexedStack(
index: _counter,
children: <Widget>[

Container(

color: Colors.grey,
alignment: Alignment.center, // where to position the child
child: Container(
child: Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"Stack 1",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
)
),
Container(

color: Colors.grey,
alignment: Alignment.center, // where to position the child
child: Container(
child: Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"Stack 2",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),

],
),
),
)
),
Container(

color: Colors.grey,
alignment: Alignment.center, // where to position the child
child: Container(
child: Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"Stack 3",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),

],
),
),
)
),
Container(

color: Colors.grey,
alignment: Alignment.center, // where to position the child
child: Container(
child: Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"Stack 4",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),

],
),
),
)
),
],
),
),

floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter(),
tooltip: 'Next page',
child: Icon(Icons.arrow_forward),
),
);

这是带有我当前代码的编辑过的帖子。

最佳答案

尝试使用PageController而不是IndexedStack checkout the docs for PageController

关于flutter - 如何实现索引堆栈之间的幻灯片过渡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56657948/

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