在 Flutter 中实现双向列表视图 [英] Implementing a bidirectional listview in Flutter
本文介绍了在 Flutter 中实现双向列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Flutter 中实现双向滚动视图?ListView 有一个 scrollDirection 字段,但它只能采用 Axis.horizontal 或 Axis.vertical.可以两者兼得吗?
How do you implement a bidirectional scroll view in Flutter? ListView has a scrollDirection field however it can only take either Axis.horizontal or Axis.vertical. Is is possible to have both?
推荐答案
这是一个使用外部 SingleChildScrollView
的潜在解决方案.你也可以使用多个 ListViews
的 PageView
,如果你对屏幕外的 ListView
被拆除没意见.
Here's a potential solution using an outer SingleChildScrollView
. You could also use a PageView
of multiple ListViews
if you're ok with the offscreen ListView
s being torn down.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyHomePage(),
));
}
class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
return new Scaffold(
body: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new SizedBox(
width: 1000.0,
child: new ListView.builder(
itemBuilder: (BuildContext context, int i) {
return new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: new List.generate(5, (int j) {
return new Text("$i,$j", style: themeData.textTheme.display2);
}),
);
},
),
),
),
);
}
}
这篇关于在 Flutter 中实现双向列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文