I get this error when i try to build my app.
Error: A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't.
(childView.primary ? PrimaryScrollController.of(context) : null);
^
Here is my complete code:
// build the customScrollView
Widget? _buildBodyBySlivers(
Widget? childView, List<Widget>? slivers, RefreshConfiguration? conf) {
Widget? body;
if (childView is! Scrollable) {
bool? primary = widget.primary;
Key? key;
double? cacheExtent = widget.cacheExtent;
Axis? scrollDirection = widget.scrollDirection;
int? semanticChildCount = widget.semanticChildCount;
bool? reverse = widget.reverse;
ScrollController? scrollController = widget.scrollController;
DragStartBehavior? dragStartBehavior = widget.dragStartBehavior;
ScrollPhysics? physics = widget.physics;
Key? center;
double? anchor;
ScrollViewKeyboardDismissBehavior? keyboardDismissBehavior;
String? restorationId;
Clip? clipBehavior;
if (childView is ScrollView) {
primary = primary ?? childView.primary;
cacheExtent = cacheExtent ?? childView.cacheExtent;
key = key ?? childView.key;
semanticChildCount = semanticChildCount ?? childView.semanticChildCount;
reverse = reverse ?? childView.reverse;
dragStartBehavior = dragStartBehavior ?? childView.dragStartBehavior;
scrollDirection = scrollDirection ?? childView.scrollDirection;
physics = physics ?? childView.physics;
center = center ?? childView.center;
anchor = anchor ?? childView.anchor;
keyboardDismissBehavior =
keyboardDismissBehavior ?? childView.keyboardDismissBehavior;
restorationId = restorationId ?? childView.restorationId;
clipBehavior = clipBehavior ?? childView.clipBehavior;
scrollController = scrollController ?? childView.controller;
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
widget.controller.scrollController = scrollController ??
childView.controller ??
(childView.primary ? PrimaryScrollController.of(context) : null);
} else {
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
widget.controller.scrollController =
PrimaryScrollController.of(context);
}
body = CustomScrollView(
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
controller: scrollController,
cacheExtent: cacheExtent,
key: key,
scrollDirection: scrollDirection ?? Axis.vertical,
semanticChildCount: semanticChildCount,
primary: primary,
clipBehavior: clipBehavior ?? Clip.hardEdge,
keyboardDismissBehavior:
keyboardDismissBehavior ?? ScrollViewKeyboardDismissBehavior.manual,
anchor: anchor ?? 0.0,
restorationId: restorationId,
center: center,
physics:
_getScrollPhysics(conf, physics ?? AlwaysScrollableScrollPhysics()),
slivers: slivers!,
dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start,
reverse: reverse ?? false,
);
} else if (childView is Scrollable) {
body = Scrollable(
physics: _getScrollPhysics(
conf, childView.physics ?? AlwaysScrollableScrollPhysics()),
controller: childView.controller,
axisDirection: childView.axisDirection,
semanticChildCount: childView.semanticChildCount,
dragStartBehavior: childView.dragStartBehavior,
viewportBuilder: (context, offset) {
Viewport viewport = childView.viewportBuilder(context, offset) as Viewport;
if (widget.enablePullDown) {
viewport.children.insert(
0,
widget.header ??
(conf?.headerBuilder != null
? conf?.headerBuilder!()
: null) ??
defaultHeader);
}
When I try to build apk with flutter it says this error on the title. I didn't understand what the problem is because I am new on development. Thanks in advance.
Also I've checked this subject but still didn't understand the solution : A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't