flutter中自定义控件
class CustomerLListTitle extends StatelessWidget {
final Widget imageData;
final String title;
CustomerLListTitle({Key key, @required this.imageData, @required this.title});
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(right:10),
child: imageData,
),
Text(title,style:TextStyle(fontSize:20,color:Colors.red))
],
);
}
}
class BanerSwiper extends StatelessWidget {
final List<dynamic> swiperDataList;
final Color backGroudColor;
BanerSwiper({Key key,this.swiperDataList,this.backGroudColor}):super(key:key);
@override
Widget build(BuildContext context) {
return Container(
color:backGroudColor,
height: ScreenUtil().setHeight(280),
width: ScreenUtil().setWidth(750),
child: Swiper(
itemBuilder: (BuildContext context,int index){
return InkWell(
onTap: (){
},
child: ClipRRect(
child: Image.network("${swiperDataList[index]['image']}",fit:BoxFit.fill),
borderRadius: BorderRadius.circular(5),
),
);
},
itemCount: swiperDataList.length,
pagination: new SwiperPagination(),
autoplay: true,
viewportFraction: 0.95,
scale: 0.9,
),
);
}
}
Widget serachBar(){
return Container(
width: ScreenUtil().setWidth(750),
height: MediaQuery.of(context).padding.top + ScreenUtil().setHeight(80),
decoration: BoxDecoration(
color: Colors.blue,
),
child: Container(
// padding: EdgeInsets.only(bottom:5),
child: Column(
children: <Widget>[
SizedBox(height:MediaQuery.of(context).padding.top + 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
width: ScreenUtil().setWidth(750) * 0.85,
height: ScreenUtil().setHeight(60),
color: Colors.white,
child:Padding(
padding: EdgeInsets.only(left:10,right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.search,color: Colors.grey,size: 26,),
Container(
// color: Colors.green,
width: 120.0,
height: 30.0,
child: TextField(
style: TextStyle(
decorationColor: Colors.red,
color: Colors.black12,
fontSize: ScreenUtil().setSp(30),
// textBaseline: TextBaseline.alphabetic
),
keyboardType: TextInputType.number,
decoration: InputDecoration(
fillColor: Colors.white30,
border: InputBorder.none, //去掉下划线
prefixStyle: TextStyle(color: Colors.grey),
contentPadding: EdgeInsets.all(8),
hintText: '请输入商品名称',
hintStyle: TextStyle(color: Colors.grey,fontSize: ScreenUtil().setSp(30))
), autofocus: false, ),
) ,
],
),
)
) ,
),
InkWell(
onTap: () { },
child: Icon(CupertinoIcons.photo_camera,color: Colors.white,size: ScreenUtil().setSp(70))
)
],
),
],
),
),
);
}
//导航组件
Widget _gridViewItemUI(BuildContext context, item, index) {
return InkWell(
onTap: () {
print("112");
},
splashColor: Util_Tool.themOpacityColor,//Theme.of(context).splashColor,
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: ScreenUtil().getHeight(15)),
Image.asset(item["imageName"],fit: BoxFit.cover,width:ScreenUtil().getWidth(36),height:ScreenUtil().getHeight(36)),
SizedBox(height: ScreenUtil().getHeight(10)),
Text(item['title'],style:TextStyle(fontSize:ScreenUtil().getSp(12),color:Colors.black,fontWeight: FontWeight.bold))
],
),
);
}
Widget _mlistTileLRnoLine(Icon leftIcon, Icon rightIcon, String title) {
//Icons.arrow_right
return Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: ListTile(
leading: leftIcon,
title: Text(
title,
textAlign: TextAlign.left,
),
trailing: rightIcon,
),
);
}
Widget _mlistTileLeftnoLine(String title, Icon leftIcon) {
// Icons.arrow_right
return Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: ListTile(
leading: leftIcon,
title: Text(
title,
textAlign: TextAlign.left,
),
),
);
}
Widget _mlistTileRightnoLine(String title, Icon rightIcon) {
// Icons.arrow_right
return Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: ListTile(
trailing: rightIcon,
title: Text(
title,
textAlign: TextAlign.left,
),
),
);
}
}