duytq94 / flutter-intro-slider

Simple and configurable app introduction slider for Flutter
https://pub.dartlang.org/packages/intro_slider
MIT License
677 stars 141 forks source link

invalid value occurs 'not in range 0..2, inclusive :3' #45

Closed johnDivek closed 4 years ago

johnDivek commented 5 years ago

════════ Exception Caught By widgets library ═══════════════════════════════════════════════════════ The following RangeError was thrown building IntroSlider(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#5ac6e]], state: IntroSliderState#7ffc0(ticker inactive)): RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 When the exception was thrown, this was the stack:

0 List.[] (dart:core-patch/growable_array.dart:145:60)

1 IntroSliderState.renderListDots (package:intro_slider/intro_slider.dart:1039:34)

2 IntroSliderState.renderBottom (package:intro_slider/intro_slider.dart:829:42)

3 IntroSliderState.build (package:intro_slider/intro_slider.dart:737:13)

4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4012:27)

duytq94 commented 5 years ago

I think you set up wrong something, please check the code example or showing your config so I can check what you did.

johnDivek commented 5 years ago

import 'package:Aor/app/providers/language_provider.dart'; import 'package:flutter/material.dart'; import 'package:intro_slider/dot_animation_enum.dart'; import 'package:intro_slider/intro_slider.dart'; import 'package:intro_slider/slide_object.dart'; import 'package:provider/provider.dart';

class IntroScreen extends StatefulWidget { IntroScreen({Key key}) : super(key: key);

@override IntroScreenState createState() => new IntroScreenState(); }

class IntroScreenState extends State { List slides = new List();

Function goToTab;

@override void initState() { super.initState(); }

void onDonePress() { // Back to the first tab Navigator.pushReplacementNamed(context, '/signUp'); }

void onTabChangeCompleted(index) { // Index of current tab is focused }

Widget renderNextBtn() { return Icon( Icons.navigate_next, color: Colors.red, size: 35.0, ); }

Widget renderDoneBtn() { return Icon( Icons.done, color: Colors.red, ); }

Widget renderSkipBtn() { return Icon( Icons.skip_next, color: Colors.red, ); }

textStyle() { return TextStyle( color: Colors.white, fontSize: 20.0, fontStyle: FontStyle.normal, fontFamily: 'AlegreyaSansSC'); }

headTextStyle() { return TextStyle( color: Colors.white, fontSize: 30.0, fontStyle: FontStyle.normal, fontFamily: 'AlegreyaSansSC'); }

List renderListCustomTabs() { List tabs = new List(); for (int i = 0; i < slides.length; i++) { Slide currentSlide = slides[i]; tabs.add(Container( width: double.infinity, height: double.infinity, child: Container( padding: EdgeInsets.all(5.0), margin: EdgeInsets.only(bottom: 60.0, top: 60.0), child: ListView( children: [ SizedBox(height: 80), Container( child: Text( currentSlide.title, style: currentSlide.styleTitle, textAlign: TextAlign.center, ), margin: EdgeInsets.only(top: 20.0), ), SizedBox(height: 25), Container( padding: EdgeInsets.fromLTRB(10, 0, 10, 0), child: Text( currentSlide.description, style: currentSlide.styleDescription, textAlign: TextAlign.center, maxLines: 5, overflow: TextOverflow.ellipsis, ), margin: EdgeInsets.only(top: 20.0), ), ], ), ), )); } return tabs; }

@override Widget build(BuildContext context) {

final languageModel = Provider.of<LanguageModel>(context);
slides.add(
  new Slide(
    title: languageModel.lang['intro1Title'],
    styleTitle: headTextStyle(),
    description: languageModel.lang['intro1Summary'],
    styleDescription: textStyle(),
  ),
);
slides.add(
  new Slide(
    title: languageModel.lang['intro2Title'],
    styleTitle: headTextStyle(),
    description: languageModel.lang['intro2Summary'],
    styleDescription: textStyle(),
  ),
);
slides.add(
  new Slide(
    title: languageModel.lang['intro3Title'],
    styleTitle: headTextStyle(),
    description: languageModel.lang['intro3Summary'],
    styleDescription: textStyle(),
  ),
);
return new IntroSlider(
  // List slides
  slides: this.slides,

  // Skip button
  renderSkipBtn: this.renderSkipBtn(),
  colorSkipBtn: Colors.black,
  highlightColorSkipBtn: Colors.red,

  // Next button
  renderNextBtn: this.renderNextBtn(),

  // Done button
  renderDoneBtn: this.renderDoneBtn(),
  onDonePress: this.onDonePress,
  colorDoneBtn: Colors.black,
  highlightColorDoneBtn: Colors.red,

  // Dot indicator
  colorDot: Colors.white,
  sizeDot: 8.0,
  typeDotAnimation: dotSliderAnimation.DOT_MOVEMENT,
  colorActiveDot: Colors.red,

  // Tabs
  listCustomTabs: this.renderListCustomTabs(),
  backgroundColorAllSlides: Colors.black,
  refFuncGoToTab: (refFunc) {
    this.goToTab = refFunc;
  },

  // Show or hide status bar
  shouldHideStatusBar: true,

  // On tab change completed
  onTabChangeCompleted: this.onTabChangeCompleted,
);

} }

johnDivek commented 5 years ago

The issue weird only occurs when the loaded from my login screen but works good from splash screen

ggichure commented 4 years ago

add how you navigate to Introscreen from login ...this seems to be an error with how you call your arrays

ajnaf commented 4 years ago

it occurs when you put the list in the build instead of the init. i want to use it in the build so i could use the S.of(context) any idea on how to use context in init method?

ajnaf commented 4 years ago

after_init 0.1.2 use this package it worked for me