我一直在构建具有水平和垂直滚动的布局。垂直可滚动Column
用于主要内容,并由不同的视图填充,包括ListView
显示促销横幅的水平视图。我想显示垂直滚动的滚动条,而不是水平滚动。我已经包裹了SingleChildScrollView
可以Column
滚动的内容ScrollBar
,但是该栏出现在水平滚动的两个垂直方向上。对这些事情有任何微调吗?
演示问题的示例
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Scrollables',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Scrollbar(
child: new SingleChildScrollView(
child: new Container(
padding: EdgeInsets.only(top: 40.0),
child: Column(children: <Widget>[
HorizontalListView(),
VerticalListView(),
]),
)),
),
);
}
}
class HorizontalListView extends StatelessWidget {
var items = new List<String>();
_addNewItem(int index) {
items.add("Item $index");
}
@override
Widget build(BuildContext context) => Container(
height: 120,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 15,
itemBuilder: (context, index) {
return Card(child: ListItem(index));
}));
}
class VerticalListView extends StatelessWidget {
var items = new List<String>();
_addNewItem(int index) {
items.add("Item $index");
}
@override
Widget build(BuildContext context) => Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: 50,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return ListItem(index);
}));
}
class ListItem extends StatelessWidget {
int _index;
ListItem(this._index);
@override
Widget build(BuildContext context) {
return Container(
width: 280,
child: Text("Item ${this._index}"),
);
}
}
注意水平滚动的底部