屏幕快照 2019-09-19 17.31.54.png
一个简单我的页面,之前做过iOS的应该知道,TableView 可以设置section header,但是ListView没有区分Section和Row。ListView有ListTile,但是我还是自定义了一个
代码语言:javascript复制import 'package:flutter/material.dart';
class MineItemWidget extends StatelessWidget {
String imageName;
String title;
@required VoidCallback onTap;
MineItemWidget(this.imageName,this.title,{this.onTap});
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Container(
height: 53,
child: _mineItem(imageName, title),
),
Container(
color: Color(0xffeaeaea),
constraints: BoxConstraints.expand(height: 1.0),
),
],
)
);
}
Widget _mineItem(String imageName,String title) {
return InkWell(
onTap: (){
this.onTap();
},
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
padding: EdgeInsets.only(left: 16),
child: Image.asset(
imageName,
width: 30,
height: 30,
),
),
),
Expanded(
flex: 6,
child: Container(
padding: EdgeInsets.only(left: 10),
child: Text(
title,
style: TextStyle(fontSize: 16),
),
),
),
Expanded(
flex: 1,
child: Container(
child: Icon(
Icons.keyboard_arrow_right,
size: 20,
color: Colors.grey,
),
),
),
],
),
);
}
}
代码语言:javascript复制 @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('我的'),
backgroundColor: Colors.deepOrange,
elevation: 0, //去掉Appbar底部阴影
),
body: ListView(
children: <Widget>[
MineHead(),
_listViewLine, // 分割线
MineItemWidget("images/tab_car_n.png","发布记录",onTap: (){
print('发布记录');
}),
MineItemWidget("images/tab_car_n.png","车主认证",onTap: (){
}),
_listViewLine,
MineItemWidget("images/tab_car_n.png","联系客服",onTap: (){
}),
],
));
}
// 分割线
Widget get _listViewLine {
return Container(
color: Color(0xffeaeaea),
height: 6,
);
}
如果使用ListView.builder初始化还需要根据index判断什么时候加在ListView中加分割线。所以使用上面这种方式。