import 'package:flutter/material.dart';
import 'package:flutterdemo/secondscreen.dart';
class ListViewDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "listview",
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return ListViewState();
}
}
class ListViewState extends State<HomePage>{
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(title: Text("listview")),
body: ListView(
children: <Widget>[
getItem("xxx"),
new Divider(), //分割线
getItem("xxx"),
new Divider(), //分割线
getItem("xxx"),
],
),
);
}
Widget getItem(String title) {
return Container(
width: 160.0,
child: new ListTile(
leading: Icon(Icons.map),
title: Text(title),
trailing: Icon(Icons.add),
subtitle: Text("xxx"),
onTap: (){
print("我被点击了");
//跳转
Navigator.push(context, new MaterialPageRoute(builder: (context) => SecondScreen()));
},
),
);
}
}