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 ...
随机推荐
- 素数是个什么东西 prime number
/** * ********************************************************************* * 只有1和它本身两个正因数的自然数,叫质数 ...
- MySQL PXC集群大事务提交超限
研发人员在测试大事务提交时遇见了错误: Got error 5 - 'Transaction size exceed set threshold' during COMMIT 测试了几次都是1200S ...
- js各种宽高的总结
1.clientWidth和clientHeight指元素的可视部分宽度和高度,就是padding+content如果没有滚动条,就是设定的宽度和高度 如果有滚动条,就是设定的宽度和高度减去滚动条的宽 ...
- 21.8 Python 使用BeautifulSoup库
BeautifulSoup库用于从HTML或XML文件中提取数据.它可以自动将复杂的HTML文档转换为树形结构,并提供简单的方法来搜索文档中的节点,使得我们可以轻松地遍历和修改HTML文档的内容.广泛 ...
- Net 高级调试之五:如何在托管函数上设置断点
一.简介 今天是<Net 高级调试>的第五篇文章.今天这篇文章开始介绍如何在托管方法和非托管方法设置断点,我们要想调试程序,必须掌握调试的一些命令,动态调试的命令,我们在上一篇文章已经讲过 ...
- Welcome to YARP - 4.限流 (Rate Limiting)
目录 Welcome to YARP - 1.认识YARP并搭建反向代理服务 Welcome to YARP - 2.配置功能 2.1 - 配置文件(Configuration Files) 2.2 ...
- Go 接口-契约介绍
Go 接口-契约介绍 目录 Go 接口-契约介绍 一.接口基本介绍 1.1 接口类型介绍 1.2 为什么要使用接口 1.3 面向接口编程 1.4 接口的定义 二.空接口 2.1 空接口的定义 2.2 ...
- [WPF]浅析资源引用(pack URI)
WPF中我们引用资源时常常提到一个概念:pack URI,这是WPF标识和引用资源最常见的方式,但不是唯一的方式.本文将介绍WPF中引用资源的几种方式,并回顾一下pack URI标识引用在不同位置的资 ...
- C语言从键盘上输入年份和月份,计算并输出这一年的这一月共有多少天。
#include<stdio.h> void main() { int y, n, s = 0;//定义变量 scanf_s("%d-%d", &y, & ...
- 金蝶云星空与吉客云电商ERP数据对接
01 系统说明: 吉客云 吉客云: 从业务数字化和组织数字化两个方向出发,以生成流程的闭环为依归,致力于为企业的数字化升级提供落地工具.销售订单层面,吉客云对接了国内外主流的销售平台,兼容了电商渠道. ...
