Flutter 搜索, 轮播, 列表构建
前言
上篇文章已说明写flutter系列项目是在的想法, 已经完成了框架的搭建, 以及底部的导航的实现.
这篇文上详情第一个导航页面的布局内容. 主要内容包括: 列表显示, 搜索框显示, 轮播图显示
效果图如下:
1.png
从上到下布局开始详情
搜索框
首先在导航文件中增加
2.png
首先新建TextFieldWidget类, 其中代码如下:
class TextFieldWidget extends StatelessWidget { Widget buildTextField() { // theme设置局部主题 return Theme( data: new ThemeData(primaryColor: Colors.grey), child: new TextField( cursorColor: Colors.grey, // 光标颜色 // 默认设置 decoration: InputDecoration( contentPadding: const EdgeInsets.symmetric(vertical: 10.0), border: InputBorder.none, icon: Icon(Icons.search), hintText: "搜索 flutter 组件", hintStyle: new TextStyle( fontSize: 14, color: Color.fromARGB(50, 0, 0, 0))), style: new TextStyle(fontSize: 14, color: Colors.black), ), ); } @override Widget build(BuildContext context) { return Container( // 修饰搜索框, 白色背景与圆角 decoration: new BoxDecoration( color: Colors.white, borderRadius: new BorderRadius.all(new Radius.circular(5.0)), ), alignment: Alignment.center, height: 36, padding: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0), child: buildTextField(), ); }}主要说明已在代码中注释, 如有疑问可以探讨
轮播图
上网查询了一下,采用的是flutter_swiper: ^1.0.6这个库, 引入一下放到pubsec.yaml文件下.即用,代码如下:
new Container( width: MediaQuery.of(context).size.width, height: 200, child: Swiper( itemCount: 3, itemBuilder: _swiperBuilder, pagination: new SwiperPagination( builder: DotSwiperPaginationBuilder( color: Colors.black54, activeColor: Colors.white, size: 5.0, activeSize: 5.0, )), scrollDirection: Axis.horizontal, autoplay: true, onTap: (index) => print('点击了第$index个')), ),_swiperBuilder方法:
Widget _swiperBuilder(BuildContext context, int index) { return (Image.network("http://via.placeholder.com/350x150", fit: BoxFit.fill)); }列表
new Expanded( child: new ListView.builder( itemCount: 10, itemBuilder: _listBuilder, ), )_listBuilder方法:
Widget _listBuilder(BuildContext context, int index) { return new Container( padding: EdgeInsets.all(10.0), margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0), decoration: new BoxDecoration( boxShadow: <BoxShadow>[ new BoxShadow( color: const Color(0x99000000), offset: new Offset(0.0, 0.5), blurRadius: 1.0, ), ], color: Colors.white, borderRadius: new BorderRadius.all(new Radius.circular(5.0)), ), child: new Row( crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ new Expanded( child: new Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ new Container( margin: new EdgeInsets.only(bottom: 10.0), child: new Text( "8篇文章, 再学不会flutter你来打我!", style: new TextStyle(fontSize: 14, color: Colors.black45), ), ), new Text( "我是作者", style: new TextStyle(fontSize: 14, color: Colors.black45), ), ], ), ), new Icon( Icons.keyboard_arrow_right, color: Colors.grey, ) ], ), ); }以上一律会展示出效果图的效果了.
重点讲解
- 1,一般组件TextField, text, image. 没有margin等属性, 需要用container包含
- 2, Expanded会撑起宽度.
- 3, Theme能设置局部主题. 一般在main中设置全局主题
下篇
下篇详情内容如下
- 1, 导航跳转介绍页面
- 2, 列表刷新加载,
- 3, 网络数据请求
说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » Flutter 搜索, 轮播, 列表构建
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » Flutter 搜索, 轮播, 列表构建