本文介绍了在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
的潜在解决方案.如果可以,并且将屏幕下的ListView
拆下,您还可以使用多个ListViews
的PageView
.
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中实现双向列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!