参数说明
参数 | 默认值 | 说明 |
---|---|---|
DataForm | 数据列表[{},{}……] | |
FrontHeight | 50.0 | 前置高度,避开搜索栏 |
pullup | 上拉回调函数 | |
dropdown | 下拉回调函数 | |
onPressed | 引用列表单元组件中使用的点击回调函数 | |
onTap | 引用列表单元组件中使用的点击回调函数 |
使用参考
配合GetX的StateMixin一起使用,等数据加载完成后再渲染列表页面,可以参考:参考链接一
class WaresView extends GetView {
var _scaffoldkey = new GlobalKey();
@override
Widget build(BuildContext context) {
var _focusNode = FocusNode();
var _controller = TextEditingController();
return Scaffold(
key: _scaffoldkey,
endDrawer: drawer,
appBar: AppBar(),
body: ConstrainedBox( //约束盒子
constraints: BoxConstraints.expand(),//不指定高和宽时则铺满整个屏慕
child: Stack(
alignment:Alignment.center , //指定对齐方式为居中
children: [
controller.obx(
(state) => Center(
child: MyListView(
DataForm: controller.dataForm,
onPressed: (item){print(item);},
onTap: (id){controller.goDetails(id);},
dropdown: (){controller.getWaresData();},
pullup: (){controller.getWaresDataAddPage();},
),
),
onError: (err) {return Text('$err');},
onLoading: Container(
width: double.infinity,
height: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 10),
Text(
"疯狂加载中...",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
],
),
),
),
Positioned(
top: 0.0,//距离顶部18px(在中轴线上,因为Stack摆放在正中间)
child: MySearchFence(
backgroundColor: Colors.white,
onSearch:(value){controller.search.text = value;controller.onInit();},
rightIcon: Icons.format_list_bulleted,//Icons.flip,
onIcon:(value){openDrawer();},
)
),
],
),
),
);
}
}
效果图
列表组件代码
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:flutter/material.dart';
// 列表聚合上拉加载下拉刷新
class MyListView extends StatefulWidget {
// 传入参数
const MyListView({
Key? key,
required this.DataForm,// 数据列表[{},{}……]
this.FrontHeight: 50.0, // 前置高度,避开搜索栏
required this.pullup, // 上拉回调函数
required this.dropdown,// 下拉回调函数
required this.onPressed,// 点击回调函数
required this.onTap,// 点击回调函数
}) : super(key: key,);
final List DataForm;
final double FrontHeight;
final ValueChanged