flutter - Flutter - 屏幕焦点在某个小部件上
问题描述
我需要帮助来执行以下操作:当我按下 List 1 时,屏幕聚焦在 List 1 上;我需要相同的其余选项
这是示例的代码: 代码
这种行为已经存在于网页中,但我在移动应用程序级别没有发现同样的行为。谢谢
解决方案
这是一个类似的小代码片段,可以帮助您实现所需的结果。
通过单击 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);
}
}
推荐阅读
- reactjs - 我没有得到切换按钮组材料 ui 的值 onchange?
- ruby-on-rails-5 - 有没有办法将另一个模型中的枚举显示到选择器中?
- content-management-system - 使用 magnolia cms 更改属性文件值
- r - ggplot2:coord_polar() 和 geom_col()
- javascript - mysql nodejs经常关闭连接
- android - 谁能帮助我如何在 Android 设备上将 java.net.Socket.connect(java.net.SocketAddress, int) 与 frida 挂钩
- python - 带有标签的pyQt5 Qslider
- javascript - 在我重新加载页面之前脚本不起作用
- c# - 使游戏对象坚不可摧
- javascript - 未附加 vue 注释