pluto_grid icon indicating copy to clipboard operation
pluto_grid copied to clipboard

[Bug] Null check operator used on a null value

Open kevinxxq opened this issue 3 years ago • 7 comments

Hi there, I updated the package recently from pluto_grid: ^4.0.1 to pluto_grid: ^5.0.4 which has break change. After that, there may be an error as below: `---------- ERROR ---------- Null check operator used on a null value

------- STACK TRACE ------- #0 LayoutState.rightFrozenLeftOffset (package:pluto_grid/src/manager/state/layout_state.dart:318) #1 PlutoGridState.updateState (package:pluto_grid/src/pluto_grid.dart:445) #2 PlutoGridState.initState. (package:pluto_grid/src/pluto_grid.dart:381) #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146) #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1091) #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997) #6 _rootRun (dart:async/zone.dart:1426) #7 _CustomZone.run (dart:async/zone.dart:1328) #8 _CustomZone.runGuarded (dart:async/zone.dart:1236) #9 _invoke (dart:ui/hooks.dart:151) #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308) #11 _drawFrame (dart:ui/hooks.dart:115)`

I can't reproduce it because the errors can't hit every time.

The code located to below code block during debugging: image

Execution Environment

Flutter version flutter doctor
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [版本 10.0.19044.1826], locale zh-CN) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6) [√] Android Studio (version 2021.2) [√] VS Code (version 1.69.2) [√] Connected device (3 available)

Thank you.

kevinxxq avatar Aug 03 '22 08:08 kevinxxq

It's hard to pinpoint the problem just from what you posted. Is the problem intermittent? Can you be more specific about what happens under what circumstances? It would be better if you attach sample code.

bosskmk avatar Aug 03 '22 20:08 bosskmk

Hi @bosskmk , Thank you for quick response.

Yes, it is very diffcicult to figure out the cause from current situation.

It is intermittent, e.g. the first time or second time to load a new page, but not sure.

Yes, I will try to collect a reproduceable sample, it is hard too, since it is on the top of heritation. I tried your demo code on my local machine, it works well, so it is from my layout.

I suspect a size constraint(may be the width) is tighten(! check) and is hitted(or get the width before its parent lay out) in the version after 4.0.1. From the record, maxWidth is null.

Now I have to rollback to 4.0.1 and I will check it by remove the layout outside plutogrid and come back to you.

Thank you.

kevinxxq avatar Aug 03 '22 23:08 kevinxxq

Can you test after modifying the /src/pluto_grid.dart file as follows? I didn't upload a separate repository because you can easily edit it.

  @override
  void initState() {
    _initStateManager();

    _initKeyManager();

    _initEventManager();

    _initOnLoadedEvent();

    _initSelectMode();

    _initHeaderFooter();

    _disposeList.add(() {
      _gridFocusNode.dispose();
    });

    // WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
    //   updateState();
    // });

    // Comment out the above line and edit it as follows
    WidgetsBinding.instance.endOfFrame.then((_) {
      updateState();
    });

    super.initState();
  }

bosskmk avatar Aug 04 '22 02:08 bosskmk

Hi @bosskmk I tried your fix code but no luck.

Anyway, please leave it here and wait for my reproduceable sample, now, it is too hard to debug or fix it.

Thank you.

kevinxxq avatar Aug 04 '22 05:08 kevinxxq

I had the same problem。

shunsen avatar Aug 19 '22 09:08 shunsen

Hi @bosskmk , Thank you evaluating it and now I have a minimum example, hope you can reproduce it on your computer. The problem may be from the tab.

Please use the file as below to reproduce it. main.zip Thank you.

kevinxxq avatar Sep 09 '22 03:09 kevinxxq

Hi @bosskmk , After I figured out the minimal example, a workround may be helpful:

                    LayoutBuilder(
                      builder: (context, constraint) {
                        if (constraint.maxWidth == 0) {
                          return Container();
                        }
                        return const PlutoGrid(
                          columns: [],
                          rows: [],
                        );
                      },
                    ),

@shunsen You can have a try on this.

Thank you.

kevinxxq avatar Sep 09 '22 04:09 kevinxxq

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 09 '22 11:10 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 23 '22 11:10 github-actions[bot]

@bosskmk This issue is still present so it should be reopened.

henry2man avatar Oct 23 '22 14:10 henry2man

@henry2man I tried the above example codes, but no problem occurred. Tested on the latest version. Flutter 3.3.4 PlutoGrid 5.3.0

If you provide a version and steps or code to reproduce the problem, we will check it out.

bosskmk avatar Oct 23 '22 14:10 bosskmk