import 'package:flutter/material.dart';
class NewsPage extends StatefulWidget{
@override
_NewsPageState createState() =>_NewsPageState();
}
class _NewsPageState extends State{
static List imgUrls =[
'http://i2.chinanews.com/simg/hd/2018/09/30/smimg_effd92c23cfa49069d23499b45be2d64.jpg',
'http://i2.chinanews.com/simg/hpic/2019/03-10/6d24b3b4dc2a438ca3d21c6e5b724036_sm.jpg',
'http://i2.chinanews.com/simg/hd/2019/01/17/smimg_80feacef0abd42478e3fda3f536f040e.jpg',
'http://www.chinanews.com/mil/2019/03-13/U776P4T8D8779333F19930DT20190313180128.jpg',
'http://www.chinanews.com/mil/2019/03-13/U776P4T8D8779494F19930DT20190313215215.jpg'
];
static List nTitles =[
'军队代表委员:强军事业展现新气象新作为',
'解放军和武警部队代表团举行第二次全体会议',
'我们,为和平而来——军队代表委员谈中国海军走向深蓝',
'“金龙-2019”中柬联合训练在柬埔寨开幕',
'燃爆!《中国军队一分钟》震撼来袭'
];
static Listlist =new List();
//新闻右侧缩略图
static Widget _rightImg(int index){
return Container(
width: 150,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10.0),
image: DecorationImage(
image: NetworkImage(imgUrls[index]),
),
),
);
}
//右侧
static Widget _leftColumn(int index) {
//样式
var titleStyle = TextStyle(color: Colors.black, fontSize: 16.0);
var tagStyle =
TextStyle(color: Color.fromARGB(255, 100, 100, 100), fontSize: 10.0);
var cateStyle=TextStyle(fontSize: 14,color: Color.fromARGB(255, 100 , 100, 100));
var timeStyle=TextStyle(fontSize: 14,color: Colors.black);
//新闻标题
var title=Text(
nTitles[index],
style: titleStyle,
maxLines: 2,
overflow: TextOverflow.ellipsis,
);
//新闻tag
var tag=Row(
children:list[index].tag.map((tag){
return Padding(
child:Container(
child: Text(tag,style: tagStyle),
padding: EdgeInsets.fromLTRB(4,2,4,2),
decoration: BoxDecoration(
color: Color.fromARGB(255, 200, 200, 200),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(10.0))
),
),
padding: EdgeInsets.only(left: 3),
);
}).toList(),
);
//新闻栏目
var cate=Text(list[index].nCate,style: cateStyle);
//发布时间
var time=Text(list[index].cTime,style: timeStyle);
//组合
return Column(
children:[
title,
Container(
margin: EdgeInsets.only(top: 8,bottom: 8),
child: tag
),
Row(
children:[
cate,time
],
),
],
);
}
var listView =ListView.builder(
itemBuilder: (BuildContext context,int index){
return Container(
margin: EdgeInsets.only(top: 10,left: 10,right: 10),
padding: EdgeInsets.only(bottom: 10),
decoration:BoxDecoration(
border:Border(bottom: BorderSide(color: Color(0xfff3f3f3),width: 0.5))
),
child: Row(
children:[
Expanded(child: _leftColumn(index)),
_rightImg(index)
],
),
);
},
);
@override
Widget build(BuildContext context) {
for(int i=0 ; i<nTitles.length-1; i++){
list.add(News(
imgUrls[i],
nTitles[i],
'热点新闻',
['头条','今日'].toList(),
'1552722410'
));
}
return Scaffold(
body:Center(child:listView),
);
}
}
class News {
String imgUrl;
String nTitle;
String nCate;
Listtag;
String cTime;
News(this.imgUrl,this.nTitle,this.nCate,this.tag,this.cTime);
}