serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.6k stars 582 forks source link

Null check operator used on a null value #229

Open volgin opened 3 years ago

volgin commented 3 years ago

This is from an automated error report from one of our users. I don't know what actions led to this exception.

monodrag.dart in DragGestureRecognizer.acceptGesture at line 324
carousel_slider.dart in _MultipleGestureRecognizer.rejectGesture at line 336
arena.dart in GestureArenaManager.sweep at line 160

I hope this is enough information to figure out what causes it.

kanhaiyhacker commented 3 years ago

I am also facing the same issue.

The following _CastError was thrown building AnimatedBuilder(animation: PageController#a54d1(one client, offset 3600000.0), dirty, state: _AnimatedState#c1ea5): Null check operator used on a null value

The relevant error-causing widget was: CarouselSlider file:///D:/external%20projects/MVSCCs/MVSCCS_APP/lib/src/widgets/HomeSliderWidget.dart:38:15 When the exception was thrown, this was the stack:

0 _CarouselSliderState.build.. (package:carousel_slider/carousel_slider.dart:159:38)

1 AnimatedBuilder.build (package:flutter/src/widgets/transitions.dart:1483:19)

2 _AnimatedState.build (package:flutter/src/widgets/transitions.dart:179:48)

3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4758:27)

4

waqaskhan409 commented 3 years ago

I'm also facing the same issue... The following _CastError was thrown building AnimatedBuilder(animation: PageController#c7a83(one client, offset 1803636.4), dirty, state: _AnimatedState#cfddc): Null check operator used on a null value

waqaskhan409 commented 3 years ago

My error was gone by using the updated package carousel_slider: ^2.3.1. May be by updating the package will solve your problem.

volgin commented 3 years ago

I am using the latest version, and still see this error. It does not happen often, but it still happens.

nehal076 commented 3 years ago

I am also facing this issue. Please provide a solution

HarisAtiq2762 commented 3 years ago

same here, I am also facing this issue

carlhung commented 3 years ago

so am I. haha

hamidamazai commented 3 years ago

Run the following commands in terminal flutter channel stable flutter upgrade

jlnrrg commented 3 years ago
I am up to date ``` Flutter is already up to date on channel stable Flutter 2.0.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision b1395592de (12 days ago) • 2021-04-01 14:25:01 -0700 Engine • revision 2dce47073a Tools • Dart 2.12.2 ```

This is a combination of two packages, so I am not certain this fits purely flutter_carousel. But I encountered the error in it's code, so pretty certain.

my code ```dart import 'package:smooth_page_indicator/smooth_page_indicator.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:carousel_slider/carousel_controller.dart'; import 'package:carousel_slider/carousel_slider.dart'; . . . @override Widget build(BuildContext context) { final ValueNotifier activeIndex = useState(0); final CarouselController _controller = CarouselController(); return Column( children: [ CarouselSlider.builder( itemCount: groupedStyles.length, options: CarouselOptions( height: 400, // viewportFraction: 1.0, enableInfiniteScroll: false, onPageChanged: (int index, _) => activeIndex.value = index), itemBuilder: (_, int index, int realIndex) { return Container(height: 100, width: 100, color: Colors.red); }), AnimatedSmoothIndicator( activeIndex: activeIndex.value, count: groupedStyles.length, effect: const WormEffect(), onDotClicked: (int index) async { debugPrint(index.toString()); await _controller.animateToPage(index); }) ], ); } ```

The problem seems to be here: (_state is null, but forced to be not)

flutter_carousel_slider code ```dart class CarouselControllerImpl implements CarouselController { CarouselState? _state; . . . Future animateToPage(int page, {Duration? duration = const Duration(milliseconds: 300), Curve? curve = Curves.linear}) async { final bool isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate; // <-- state is null if (isNeedResetTimer) { _state!.onResetTimer(); } final index = getRealIndex(_state!.pageController!.page!.toInt(), _state!.realPage - _state!.initialPage, _state!.itemCount); _setModeController(); await _state!.pageController!.animateToPage( _state!.pageController!.page!.toInt() + page - index, duration: duration!, curve: curve!); if (isNeedResetTimer) { _state!.onResumeTimer(); } } ```
diyarfaraj commented 3 years ago

having same problem here. Any solution anyone?

Have tried these links below, but none of them helped much: https://stackoverflow.com/questions/64822800/null-check-operator-used-on-a-null-value-carousel-flutter https://stackoverflow.com/questions/64278595/null-check-operator-used-on-a-null-value

EDIT: Updating it to the latest version somehow solved it.

omidraha commented 3 years ago

Same issue. Related: https://github.com/flutter/flutter/issues/66250 https://stackoverflow.com/questions/64822800/null-check-operator-used-on-a-null-value-carousel-flutter

viciainc commented 3 years ago

This worked for me

So I edited scrollposition.dart package

from line 133 @override //double get minScrollExtent => _minScrollExtent!; // double? _minScrollExtent; double get minScrollExtent { if (_minScrollExtent == null) { _minScrollExtent = 0.0; } return double.parse(_minScrollExtent.toString()); }

double? _minScrollExtent;

@override // double get maxScrollExtent => _maxScrollExtent!; // double? _maxScrollExtent; double get maxScrollExtent { if (_maxScrollExtent == null) { _maxScrollExtent = 0.0; } return double.parse(_maxScrollExtent.toString()); }

double? _maxScrollExtent;

hamid1245 commented 3 years ago

also facing the same issue

JuanSuarezZ commented 2 years ago

the same issue

rihemebh commented 1 year ago

I am facing the same issue here and I am using the latest version is there any update ?

image