6、Flutter 列表组件 滑动
列表有以下分类:
1、垂直列表
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: ListView (children: const [
Icon(Icons.search, color: Colors.red, size: 50),
SizedBox(height: 100),
Icon(ItyingIcon.weix, size: 50, color: Color.fromARGB(255, 9, 240, 151)),
SizedBox(height: 100),
Icon(ItyingIcon.gouwu, size: 50, color: Colors.black),
SizedBox(height: 100),
Icon(ItyingIcon.weix, size: 50, color: Color.fromARGB(255, 27, 71, 54)),
],)
);
}
}
2、垂直图文列表
class MyApp1 extends StatelessWidget {
const MyApp1({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
children: <Widget>[
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
],
);
}
}
3、水平列表
class MyApp2 extends StatelessWidget {
const MyApp2({super.key});
@override
Widget build(BuildContext context) {
return SizedBox( //指定固定尺寸
// width: 100.0,
height: 100.0,
child: ListView(
scrollDirection: Axis.horizontal, //水平
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
children: <Widget>[
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
Image.network(
"https://dashanbook.oss-cn-shenzhen.aliyuncs.com/46aa6e030985487894f34196c4df3ee4.jpg"),
],
)
);
}
}
4、动态列表
(1)for循环实现动态列表
class MyApp3 extends StatelessWidget {
MyApp3({Key? key}) : super(key: key) {
print(ListText);
}
List<Widget> _initListData() {
List<Widget> list = [];
for (var i = 0; i < ListText.length; i++) {
list.add(ListTile(
leading: Image.network("${ListText[i]["imageUrl"]}"),
title: Text("${ListText[i]["title"]}"),
subtitle: Text("${ListText[i]["author"]}"),
));
}
return list;
}
@override
Widget build(BuildContext context) {
return ListView(children: _initListData());
}
}
(2)map实现动态列表
class MyApp4 extends StatelessWidget {
MyApp4({Key? key}) : super(key: key) {
print(ListText);
}
List<Widget> _initListData() {
var list = ListText.map((value) {
return ListTile(
leading: Image.network("${value["imageUrl"]}"),
title: Text("${value["title"]}"),
subtitle: Text("${value["author"]}"),
);
});
return list.toList();
}
@override
Widget build(BuildContext context) {
return ListView(children: _initListData());
}
}
(3)ListView.builder实现动态列表
class MyApp5 extends StatelessWidget {
List<String> list = [];
MyApp5({Key? key}) : super(key: key) {
for (var i = 0; i < 30; i++) {
list.add("数据$i");
}
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: list.length, //循环的次数
itemBuilder: (context, index) {
return ListTile(
title: Text("${list[index]}"),
);
},
);
}
}
6、Flutter 列表组件 滑动的更多相关文章
- ListView 基础列表组件、水平 列表组件、图标组件
一.Flutter 列表组件概述 列表布局是我们项目开发中最常用的一种布局方式.Flutter 中我们可以通过 ListView 来定义 列表项,支持垂直和水平方向展示.通过一个属性就可以控制列表的显 ...
- Flutter中的可滚动列表组件-PageView
PageVIew,可滚动的视图列表组件,而且每一个子组件的大小都和视图窗口大小一样. 属性: controller -> PageController 用于控制视图页面滚动到的位置 childr ...
- Flutter学习笔记(12)--列表组件
如需转载,请注明出处:Flutter学习笔记(12)--列表组件 在日常的产品项目需求中,经常会有列表展示类的需求,在Android中常用的做法是收集数据源,然后创建列表适配器Adapter,将数据源 ...
- Flutter 实战(一):列表项内容可自定义的列表组件
前言 本篇文的目的是熟练掌握 Flutter 组件的封装,并且使用回调函数实现主要功能. 本组件的设计灵感来源于 Element 组件库的 table 组件. 正题 定义回调函数 在此之前,必须要了解 ...
- React-Native新列表组件FlatList和SectionList学习 | | 联动列表实现
React-Native在0.43推出了两款新的列表组件:FlatList(高性能的简单列表组件)和SectionList(高性能的分组列表组件). 从官方上它们都支持常用的以下功能: 完全跨平台. ...
- Flutter常用组件(Widget)解析-ListView
一个可滚动的列表组件 不管在哪,列表组件都尤为重要和常用. 首先来看个例子: import 'package:flutter/material.dart'; void main () => ru ...
- 07Flutter ListView基础列表组件、水平列表组件、图标组件
ListView: ListView:参数 scrollDirection:Axis.horizontal:水平列表.Axis.vertical垂直列表 padding:内边距 ...
- Flutter ListTile - Flutter每周一组件
该文章属于[Flutter每周一组件]系列,其它组件可以查看该系列下的文章,该系列会不间断更新:所有组件的demo已经上传值Github: https://github.com/xj124456/fl ...
- 列表组件抽象(2)-listViewBase说明
这是我写的关于列表组件的第2篇博客.前面的相关文章有: 1. 列表组件抽象(1)-概述 listViewBase是列表组件所有文件中最核心的一个,它抽象了所有列表的公共逻辑,将来如果有必要添加其它公共 ...
- 可展开的列表组件——ExpandableListView深入解析
可展开的列表组件--ExpandableListView深入解析 一.知识点 1.ExpandableListView常用XML属性 2.ExpandableListView继承BaseExpanda ...
随机推荐
- bash: accelerate: command not found
py AIGC Stable Diffusion文生图Lora模型微调实现虚拟上装详情 实验手册 实验报告 3. 安装Diffusers 进入PAI-DSW开发环境. 登录PAI控制台. ...
- wps 设置 word文档不可被修改,指定区域可以修改
wps 设置 word文档不可被修改,指定区域可以修改 2021年03月03日09:38:10
- 惊奇!Android studio内部在调用Eclipse
现在用Android studio的人越来越多,主要是说谷歌不再支持Eclipse,而力推Android studio.但是as也太不给力了,我之前写过一篇博客提到. 今天要说的是一个惊天的消息,如题 ...
- Unity3D ConfigMan.cs For XML File
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- JavaScript:数据类型详解
ECMAScript中数据类型目前有两种:基本数据类型和引用数据类型. 基本数据类型 基本数据类型也称作简单数据类型,为Undefined,Null,Boolean,Number,String,Sym ...
- 服务器没有开放3306端口 远程访问MySQL数据库方法
一.前言 当装有MySQL的服务器为了防止数据库被黑,提高安全性,把3306端口禁止掉,禁止对外访问,我之前写过一篇是借助跳板机的SSH隧道来访问实现安全,这种情况依然需要开放3306端口和使用一 ...
- Ansible操作MySQL常用的几个模块
1. mysql_user 模块 mysql_user模块用来添加,删除用户以及设置用户权限 创建MySQL数据库的用户与口令(非root@localhost用户),直接通过playbooks中的案例 ...
- 花了三年时间开发的开源项目,终于500 个 Star 了!
waynboot-mall 商城项目从疫情开始初期着手准备,到现在已经经过了 3 年多的时间,从项目初期到现在,一个人持续迭代,修复漏洞,添加功能,经历了前端开发工具从 vue2.vue-cli 切换 ...
- musl中strlen源码实现和分析
最近在学习<C 和指针>的第 6 章指针部分,在 6.12 章节看到了 strlen 函数的实现,联想到最近有在看 musl 的源码,于是就把 musl 中 strlen 的源码认真地分析 ...
- markdown语法基本使用
markdown 语法基本使用 目录 markdown 语法基本使用 各级标题 字体 引用 分隔线 图片 列表 表格 代码 超链接 各级标题 井号加上空格,几级标题用几个井号加上空格 字体 单星号引起 ...
