gpt4 book ai didi

flutter - Flutter-屏幕聚焦于某个小部件

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

我需要帮助来执行以下操作:当我按列表1时,屏幕将聚焦在列表1上;其余选项我都需要



这是示例的代码:
code

网页中已经存在此行为,但是在移动应用程序级别上却没有发现相同的行为。谢谢

最佳答案

这是类似内容的一小段代码,可能有助于您达到所需的结果。

通过单击fab图标,它将向下滚动到ListView中的项目35。

class MyHomePage extends StatelessWidget {
final _scrollController = ScrollController();
final _cardHeight = 200.0;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.orange,
onPressed: () => _animateToIndex(35),
child: Icon(Icons.add),
),
body: ListView.builder(
controller: _scrollController,
itemCount: 100,
itemBuilder: (_, i) => Container(
height: _cardHeight,
child: Card(
color: Colors.lightBlue,
child: Center(
child: Text("Scroll Item $i", style: TextStyle(fontSize: 28.0),),
),
),
),
),
);
}

_animateToIndex(index) {
_scrollController.animateTo(_cardHeight * index,
duration: Duration(seconds: 1), curve: Curves.fastOutSlowIn);
}
}

关于flutter - Flutter-屏幕聚焦于某个小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60415447/

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