上拉加载和下拉刷新失效问题
来源:10-5 高级功能列表下拉刷新与上拉加载更多功能实现【列表拓展技能】
慕工程8106173
2019-05-15
老师,我的下拉刷新本来是好用的,可是加上上拉加载后,下拉刷新就失效了,上拉加载也不起作用了。不知道是什么原因造成的。
源码如下:
import ‘package:flutter/material.dart’;
import ‘package:ifa_flutter/dao/inventory_total_dao.dart’;
import ‘dart:convert’;
import ‘package:ifa_flutter/model/inventory_total_model.dart’;
import ‘package:ifa_flutter/widget/inventory_total_item_nav.dart’;
class InventoryTotalListPage extends StatefulWidget {
@override
_InventoryTotalListPageState createState() => _InventoryTotalListPageState();
}
class _InventoryTotalListPageState extends State {
InventoryTotalModel model = null;
int state = 1;
ScrollController _scrollController = ScrollController();
int number = 1;
@override
void initState() {
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
loadData();
}
});
super.initState();
loadData();
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
loadData() async {
try {
model = await InventoryTotalDao.fetch(number++);
setState(() {});
} catch (e) {}
}
Future _handleRefresh() async {
number = 1;
loadData();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘资产盘点’),
),
body: RefreshIndicator(
onRefresh: _handleRefresh,
child: ListView(
controller: _scrollController,
children: [
Container(
child: Column(
children: [
Card(
child: Container(
height: 50,
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: _setSate1,
child: Text(‘进行中’),
)),
Expanded(
child: GestureDetector(
child: Text(‘已结束’),
onTap: _setSate2,
)),
],
),
),
),
InventoryTotalItemNav(
inventoryTotalModel: model == null ? null : model,
state: state,
),
],
))
],
),
),
);
}
_setSate1() {
setState(() {
state = 1;
});
}
_setSate2() {
setState(() {
state = 2;
});
}
}
望老师答疑
2回答
-
CrazyCodeBoy
2019-05-16
~~~~(>_<)~~~~,通过编辑器中的代码的形式贴出来吧
00 -
慕粉3464179
2019-05-15
心疼老师,这个没格式化的代码看的头疼
022019-05-21
相似问题