107 lines
3.0 KiB
Dart
107 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/*
|
|
* 仿微信--------------------------发现
|
|
*
|
|
* 详细信息封装
|
|
*
|
|
* 添加点击使用的是 GestureDetector 将Container或者Widget包装起来;
|
|
*
|
|
* (1)onTap: 点击时的回调,需要调用setState(() {}刷新;
|
|
* (2)onTap: 点击时的回调,需要调用setState(() {}刷新;
|
|
* (3)onTapCancel: 手势取消调用,比如点击后继续滑动到其他地方,这时候不需要跳转,但颜色需要改回白色,需要调用setState(() {}刷新;
|
|
* (4)使用Navigator进行界面的跳转,没有参数的话直接调用push()方法;
|
|
* (5)固定用法:使用MaterialPageRoute创建回调;
|
|
*/
|
|
|
|
class DiscoverListViewCellPage extends StatefulWidget {
|
|
final String title;
|
|
final String subTitle;
|
|
final String imageName;
|
|
final String subImagename;
|
|
|
|
const DiscoverListViewCellPage(
|
|
{Key key, this.title, this.subTitle, this.imageName, this.subImagename})
|
|
: assert(title != null, 'title 不能为空'),
|
|
assert(imageName != null, 'imageName 不能为空');
|
|
|
|
@override
|
|
_DiscoverListViewCellPageState createState() =>
|
|
_DiscoverListViewCellPageState();
|
|
}
|
|
|
|
class _DiscoverListViewCellPageState extends State<DiscoverListViewCellPage> {
|
|
//定义主题颜色
|
|
Color _StateBackColor = Colors.white;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) {
|
|
return null;
|
|
}
|
|
),
|
|
);
|
|
setState(() {
|
|
_StateBackColor = Colors.white;
|
|
});
|
|
},
|
|
|
|
onTapDown: (TapDownDetails details){
|
|
setState(() {
|
|
_StateBackColor = Colors.grey[100];
|
|
});
|
|
},
|
|
|
|
onTapCancel: (){
|
|
print('onTapCance----');
|
|
setState(() {
|
|
_StateBackColor = Colors.white;
|
|
});
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
color: _StateBackColor,
|
|
height: 54,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
Row(
|
|
children: <Widget>[
|
|
Image(width: 30, height: 30, image: AssetImage(widget.imageName)),
|
|
SizedBox(
|
|
width: 30,
|
|
),
|
|
Text(widget.title,
|
|
style: TextStyle(
|
|
fontSize: 18
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: <Widget>[
|
|
Text(widget.subTitle != null ? widget.subTitle : ''),
|
|
SizedBox(
|
|
width: 15,
|
|
),
|
|
widget.subImagename != null
|
|
? Image(width: 15, image: AssetImage(widget.subImagename))
|
|
: Container(),
|
|
SizedBox(width: 15),
|
|
Image(width: 20, image: AssetImage('assets/images/icon_right.png')),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
|
|
),
|
|
);
|
|
}
|
|
}
|