xuelongqy / flutter_easy_refresh

A flutter widget that provides pull-down refresh and pull-up load.
https://xuelongqy.github.io/flutter_easy_refresh/
MIT License
3.92k stars 636 forks source link

Null check operator used on a null value #637

Closed xyhuangjia closed 1 year ago

xyhuangjia commented 2 years ago

版本 easy_refresh: ^3.0.4+3

代码

view

class MessageView extends GetView<MessageController> {
  const MessageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          appBar: AppBar(
            title: Text(controller.appBarTitle.value),
            actions: [
              IconButton(onPressed: () {}, icon: const Icon(Icons.notifications))
            ],
          ),
          body: EasyRefresh(
              refreshOnStart: true,
              controller: controller.easyRefreshController,
              onRefresh: () => controller.onRefresh(),
              onLoad: () => controller.onLoad(),
              child: CustomListView(
                builder: (int index) =>
                    buildItem(index, controller.dataList.value[index]),
                dataList: controller.dataList.value,
              )),
        ));
  }
/// 自定义ListView
class CustomListView extends StatelessWidget {
  const CustomListView(
      {Key? key,
      required this.builder,
      required this.count,
      this.padding = EdgeInsets.zero,
      this.space = 5.0})
      : super(key: key);

  /// 单元格
  final Function(int index) builder;

  /// 数据源数据
  final int count;

  final EdgeInsets padding;

  final double space;

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        count == 0
            ? const SliverFillRemaining(child: EmptyView())
            : SliverToBoxAdapter(child: Container()),
        SliverPadding(
          padding: padding,
          sliver: SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) {
                final int itemIndex = index ~/ 2;
                if (index.isEven) {
                  return builder.call(itemIndex);
                }
                return Divider(height: space, color: Colors.transparent);
              },
              semanticIndexCallback: (Widget widget, int localIndex) {
                if (localIndex.isEven) {
                  return localIndex ~/ 2;
                }
                return null;
              },
              childCount: max(0, count * 2 - 1),
            ),
          ),
        ),
      ],
    );
  }
}

异常信息

======== Exception caught by scheduler library =====================================================
The following _CastError was thrown during a scheduler callback:
Null check operator used on a null value

When the exception was thrown, this was the stack: 
#0      IndicatorNotifier._canProcess (package:easy_refresh/src/notifier/indicator_notifier.dart:245:40)
#1      IndicatorNotifier.callTask (package:easy_refresh/src/notifier/indicator_notifier.dart:396:59)
#2      _EasyRefreshState._callRefresh (package:easy_refresh/src/easy_refresh.dart:427:28)
#3      _EasyRefreshState.initState.<anonymous closure>.<anonymous closure> (package:easy_refresh/src/easy_refresh.dart:295:11)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#5      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:9)
#6      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015:5)
#7      _invoke (dart:ui/hooks.dart:148:13)
#8      PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#9      _drawFrame (dart:ui/hooks.dart:115:31)
xyhuangjia commented 1 year ago

@xuelongqy 这个是又是和NavibottomBar放在一起使用的

xuelongqy commented 1 year ago

我不能准确的定位问题,但看起来是EasyRefresh已经dispose了,看看是否有频繁的状态更新。有简单完整的复现demo就更好了

xyhuangjia commented 1 year ago

我不能准确的定位问题,但看起来是EasyRefresh已经dispose了,看看是否有频繁的状态更新。有简单完整的复现demo就更好了

已经找到问题所在,我这就关掉

zhongzf1 commented 1 year ago

我不能准确的定位问题,但看起来是EasyRefresh已经dispose了,看看是否有频繁的状态更新。有简单完整的复现demo就更好了

已经找到问题所在,我这就关掉

请问你是怎么解决的?我也遇到了