Reputation: 47
Using flutter_inner_drawer: ^1.0.0+1
I got a error thats is type
'List<Widget?>' is not a subtype of type 'List' in type cast
my code:
final GlobalKey<InnerDrawerState> _innerDrawerKey =
GlobalKey<InnerDrawerState>();
InnerDrawer(
key: _innerDrawerKey,
onTapClose: true, // default false
swipe: true, // default true
colorTransitionChild: Colors.red, // default Color.black54
colorTransitionScaffold: Colors.black54, // default Color.black54
//When setting the vertical offset, be sure to use only top or bottom
offset: const IDOffset.only(bottom: 0.05, right: 0.0, left: 0.0),
scale:
const IDOffset.horizontal(0.8), // set the offset in both directions
proportionalChildArea: true,
borderRadius: 50, // default 0
leftAnimationType: InnerDrawerAnimation.static,
rightAnimationType: InnerDrawerAnimation.quadratic,
backgroundDecoration: const BoxDecoration(
color: Colors.red), /
onDragUpdate: (double? val, InnerDrawerDirection? direction) {
print(val);
print(direction == InnerDrawerDirection.start);
},
innerDrawerCallback: (a) =>
print(a),
leftChild: Container(),
scaffold: Scaffold(
appBar: AppBar(automaticallyImplyLeading: false),
)
);
how can I salve this error?
Upvotes: 2
Views: 216
Reputation: 63799
This issue is coming from the source code. You can check the git Issue
The issue is coming from L435-L437
final Widget scaffoldChild = Stack(
children: <Widget?>[widget.scaffold, invC != null ? invC : null]
.where((a) => a != null)
.toList() as List<Widget>,
);
children
doesn't accept any nullable widget.
Also, _trigger(..)
method returning nullable widget L544-L563
And It is being used on L600-L620
While the children can't be null anymore, we can remove or replace _trigger()
widget when it returns null.
You can solve by making children not nullable.
In that case scaffoldChild
will be
final Widget scaffoldChild = Stack(
children: <Widget>[
widget.scaffold,
if (invC != null) invC,
].toList(),
);
null check while using _trigger(..)
or provide default value like
_trigger(AlignmentDirectional.centerStart, _leftChild) ??
SizedBox(),
_trigger(AlignmentDirectional.centerEnd, _rightChild) ??
SizedBox(),
].toList(),
Make sure to replace
<Widget?>[
with<Widget>[
There is an easy solution from others repo: you can follow this comment which says
Hi, i used a pull request. In the pubspec.yaml, i change for this:
flutter_inner_drawer:
git:
url: https://github.com/kenjishiromajp/flutter_inner_drawer
ref: kenjishiromajp-update-for-2.12-null-safety-casting
Upvotes: 2