Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in null-safety mode #70

Open
ykrank opened this issue Apr 14, 2021 · 10 comments
Open

Crash in null-safety mode #70

ykrank opened this issue Apr 14, 2021 · 10 comments

Comments

@ykrank
Copy link

ykrank commented Apr 14, 2021

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

The relevant error-causing widget was:
InnerDrawer-[LabeledGlobalKey#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)

@pythoneer
Copy link

pythoneer commented Apr 15, 2021

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
Copy link

pythoneer commented Apr 19, 2021

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
Copy link

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: #69

@rafaelsetragni
Copy link

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

@pythoneer
Copy link

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.

@AliHoseinpoor
Copy link

i have the same problem

@mqhamdam
Copy link

mqhamdam commented Jul 4, 2021

coming with same issue

@AliHoseinpoor
Copy link

can you fix this issue ?

@mqhamdam
Copy link

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

see there:
#73

@meg4cyberc4t
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants