flutter_carousel_slider icon indicating copy to clipboard operation
flutter_carousel_slider copied to clipboard

Null check operator used on a null value

Open volgin opened this issue 3 years ago • 15 comments

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.

volgin avatar Nov 15 '20 03:11 volgin

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

kanhaiyhacker avatar Nov 15 '20 11:11 kanhaiyhacker

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 avatar Nov 20 '20 06:11 waqaskhan409

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

waqaskhan409 avatar Nov 20 '20 06:11 waqaskhan409

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

volgin avatar Nov 20 '20 22:11 volgin

I am also facing this issue. Please provide a solution

nehal076 avatar Feb 02 '21 07:02 nehal076

same here, I am also facing this issue

HarisAtiq2762 avatar Mar 12 '21 15:03 HarisAtiq2762

so am I. haha

carlhung avatar Mar 14 '21 15:03 carlhung

Run the following commands in terminal flutter channel stable flutter upgrade

hamidamazai avatar Mar 24 '21 12:03 hamidamazai

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

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<int> 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
class CarouselControllerImpl implements CarouselController {

  CarouselState? _state;
.
.
.
  Future<void> 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();
    }
  }

jlnrrg avatar Apr 13 '21 09:04 jlnrrg

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.

diyarfaraj avatar Apr 14 '21 08:04 diyarfaraj

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

omidraha avatar Apr 14 '21 17:04 omidraha

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;

viciainc avatar May 09 '21 12:05 viciainc

also facing the same issue

hamid1245 avatar Oct 02 '21 11:10 hamid1245

the same issue

JuanSuarezZ avatar Dec 05 '21 17:12 JuanSuarezZ

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

image

rihemebh avatar Mar 05 '23 16:03 rihemebh