代码:
import 'package:flutter/material.dart';
void main() => runApp(MyTestApp());
class MyTestApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
title: 'Flutter test',
home: Scaffold(
appBar: new AppBar(title: new Text('ListView'),),
body: Center(
child: Container(
height: 200.0,
child: MyList()
),
)
),
);
}
}
class MyList extends StatelessWidget{
@override
Widget build(BuildContext context){
return ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
new Container(
180.0,
color: Colors.lightBlue,
),
new Container(
180.0,
color: Colors.black,
),
new Container(
180.0,
color: Colors.purple,
)
],
);
}
}
总结:
scrollDirection:Axis.horizontal // listView 横向滚动
//拆分listView 为一个组件 相当于一个函数
class MyList extends StatelessWidget{
@override
Widget build(BuildContext context){
return ListView(
);
}
}