flutter_carousel_slider icon indicating copy to clipboard operation
flutter_carousel_slider copied to clipboard

Potentially unintended null-safe handling in nextPage

Open rgb1380 opened this issue 2 years ago • 0 comments

  Future<void> nextPage(
      {Duration? duration = const Duration(milliseconds: 300),
      Curve? curve = Curves.linear}) async {
    final bool isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
    if (isNeedResetTimer) {
      _state!.onResetTimer();
    }
    _setModeController();
    await _state!.pageController!.nextPage(duration: duration!, curve: curve!);
    if (isNeedResetTimer) {
      _state!.onResumeTimer();
    }
  }

duration and curve are nullable but then you have duration! and curve! that indicate you don't expect them to be null. The same issue exists with previousPage.

You should do this instead:

 Future<void> nextPage(
     {Duration? duration,
     Curve? curve}) async {
duration ??= const Duration(milliseconds: 300);
curve ??= Curves.linear;
   final bool isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;
   if (isNeedResetTimer) {
     _state!.onResetTimer();
   }
   _setModeController();
   await _state!.pageController!.nextPage(duration: duration!, curve: curve!);
   if (isNeedResetTimer) {
     _state!.onResumeTimer();
   }
 }

rgb1380 avatar Aug 02 '21 04:08 rgb1380