flutter_inner_drawer icon indicating copy to clipboard operation
flutter_inner_drawer copied to clipboard

Crash in null-safety mode

Open ykrank opened this issue 3 years ago • 10 comments

type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast

The relevant error-causing widget was: InnerDrawer-[LabeledGlobalKey<InnerDrawerState>#e0d93] When the exception was thrown, this was the stack: #0 InnerDrawerState.build (package:flutter_inner_drawer/inner_drawer.dart:634:52) #1 StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27) #2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15) #3 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11) #4 Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)

ykrank avatar Apr 14 '21 05:04 ykrank

having the same problem after upgrading my project to Flutter2 null-safety. Haven't build a minimal example yet because i was of the impression that it has something to do with my client code. But after erasing almost all of my code i was left with an almost bare bones version of the InnerDrawer. I am about to create a project from scratch just to make sure.

flutter doctor:

$> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.4, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2020.3)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.

pubspec.yaml entry flutter_inner_drawer: ^1.0.0+1

runtime error message:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _CastError was thrown building InnerDrawer-[LabeledGlobalKey<InnerDrawerState>#146ed](dirty, dependencies: [MediaQuery, _EffectiveTickerMode], state: InnerDrawerState#d921d(ticker inactive)):
type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast

The relevant error-causing widget was: 
  InnerDrawer-[LabeledGlobalKey<InnerDrawerState>#146ed] file:///home/naikon/Documents/arbeit/dev/git-repos/academic-lapp-mobile/lib/screen/main2.dart:164:16
When the exception was thrown, this was the stack: 
#0      InnerDrawerState._scaffold (package:flutter_inner_drawer/inner_drawer.dart:437:21)
#1      InnerDrawerState.build (package:flutter_inner_drawer/inner_drawer.dart:614:55)
#2      StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27)
#3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)
#4      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════════════════════════
Null check operator used on a null value
════════════════════════════════════════════════════════════════════════════════════════════════════

EDIT1: I have build a minimal example and it is working. But i can't spot an obvious difference to the code i use in my regular application. The only obvious thing is that in my regular application the InnerDrawer is deeper nested into the widget tree but i don't think this is really relevant but i am trying to recreate this anyway because i don't see any other relevant difference.

pythoneer avatar Apr 15 '21 06:04 pythoneer

Sorry i don't know what exactly i did wrong in my first attempt to create a minimal example. Today i tried it a second time and i could fully recreate the problem and have a reproducible crash example.

pubspec.yaml

name: inner_drawer_flutter2_test
description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=2.12.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  flutter_inner_drawer: ^1.0.0+1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

main.dart

import 'package:flutter/material.dart';
import 'package:flutter_inner_drawer/inner_drawer.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return InnerDrawer(
        rightChild: Center(
            child: Text(
          "drawer",
          style: TextStyle(color: Colors.white),
        )),
        scaffold: Scaffold(
          body: Center(child: Text("body")),
        ));
  }
}

This is crashing immediately after the application starts with the error shown in my comment above. This is happening on my Pixel 4 with Android 11 but i don't think it matters.

inner_drawer_crash

pythoneer avatar Apr 19 '21 20:04 pythoneer

As i see it, there is a PR pending that is fixing this error. I was closing my PR in favor to the one that was already there and has an equivalent fix to mine (i just didn't look out for an existing PR because i thought i would be already merged by now)

the PR in question: https://github.com/Dn-a/flutter_inner_drawer/pull/69

pythoneer avatar Apr 22 '21 09:04 pythoneer

I did a fix for this error. The pull request is in Fix for cast widget list for dart null safety

rafaelsetragni avatar May 24 '21 23:05 rafaelsetragni

Hi @rafaelsetragni there are already multiple PRs for fixing this. I closed mine in favor for the PR that was already there #69 and i don't think the problem is a shortage of PRs to fix the problem. The main problem is merging and releasing the Fix that is already there.

pythoneer avatar May 25 '21 07:05 pythoneer

i have the same problem

AliHoseinpoor avatar Jun 27 '21 08:06 AliHoseinpoor

coming with same issue

mqhamdam avatar Jul 04 '21 11:07 mqhamdam

can you fix this issue ?

AliHoseinpoor avatar Jul 15 '21 06:07 AliHoseinpoor

I just downloaded all package source code and changed it as mentioned in the pull request.

see there: https://github.com/Dn-a/flutter_inner_drawer/pull/73

mqhamdam avatar Jul 15 '21 07:07 mqhamdam

I caught the same exception, but I see that you stopped discussing it in 2021. As a result, is there a solution?

meg4cyberc4t avatar May 01 '22 22:05 meg4cyberc4t