Limbou / expandable_page_view

MIT License
86 stars 36 forks source link

Getting range error on widget update. #17

Closed ssshashank closed 2 years ago

ssshashank commented 3 years ago

Implementation:- I am implementing an Expandable_Page_View that helps achieve the dynamic height of the widget based on its children height. So I have taken a list and iterating that list to display the Expandable_Page_View.

Error:- When I am removing elements from last in the list the Expandable_Page_View is throwing Range Error.

class _MyHomePageState extends State<MyHomePage> {

 //LIST 
  List<String> tempList=[
    "One","Two","Three"
  ];

//RETURN LIST OF WIDGET

  List<Widget> printWidget(){
    List<Widget> temp=[];
    for(int i=0;i<tempList.length;i++){
      temp.add(
        Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Text(tempList[i]),
              GestureDetector(
                onTap: (){
                  setState(() {
                    tempList.removeAt(i);
                  });
                },
                child: Icon(Icons.delete),
              )
            ],
          ),
        )
      );
    }
    return temp;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("AppBar"),
      ),
      body: Column(
        children: [
          ExpandablePageView.builder(
            animateFirstPage: true,
            estimatedPageSize: 100,
            itemCount: tempList.length,
            itemBuilder: (context, index) {
              return ExamplePage(
                color:  Colors.blue,
                tempList:  tempList,
                index: index,
                text:  tempList[index],
                height:  (index + 1) * 100.0,
              );
            },
          ),
        ],
      ),
    );
  }
}

class ExamplePage extends StatefulWidget {
  final Color color;
  final String text;
   List<String> tempList;
   int index;
  final double height;

   ExamplePage({this.color, this.text, this.tempList,this.index,this.height});

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: widget.height,
      color: widget.color,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Text(widget.text),
          GestureDetector(
            onTap: (){
              setState(() {
                widget.tempList.removeAt(widget.index);
              });
            },
            child: Icon(Icons.delete),
          )
        ],
      )
    );
  }
} 
derekpitts28 commented 3 years ago

I am also having this issue! Would be great to get this fix soon, may have to change plugins.

Limbou commented 3 years ago

Should be fixed with #19 , released in version 1.0.7

rahuldubey093 commented 2 years ago

The issue is still happening for me when the state is changed via change notifier and an item is removed.

Limbou commented 2 years ago

@rahuldubey093 Could you provide a minimal reproducible example?

git-maven commented 2 years ago

@rahuldubey093 Could you provide a minimal reproducible example?

For example, i have five counts page, and i selcted the third index. next i rebuild a the expanablePageView, and now i have one count page, it will be cause error

the error code is :

_heights[_currentPage] = currentPageHeight;

Limbou commented 2 years ago

Should be fixed with #24, released in version 1.0.10

Panimaster commented 2 years ago

I still have this issue (plugin version: 1.0.14, flutter 3.0.1)

Description:

We have a carousel with multiple notification cards the user can read and delete afterwards. They might have a different height and this is the main reason we are using this plugin.

In general everything works great. However when the user first swipes through all the cards (e.g. from card 1 to card 3), then back to the first one and afterwards dismisses the card (this removes the notification from the array), we are seeing the following error:

Error code:

`════════ Exception caught by widgets library ═══════════════════════════════════ The following RangeError was thrown building ExpandablePageView(dirty, state: _ExpandablePageViewState#6110c): RangeError (index): Invalid value: Only valid value is 0: 1

The following RangeError was thrown building ExpandablePageView(dirty, state: _ExpandablePageViewState#6110c): RangeError (index): Invalid value: Only valid value is 0: 1

The relevant error-causing widget was ExpandablePageView lib/…/notification_carousel/notification_carousel.dart:65 When the exception was thrown, this was the stack `

Limbou commented 2 years ago

Hi @Panimaster Could you provide some small reproducible example so I can easily find what the issue is?

Panimaster commented 2 years ago

Hey @Limbou : i forked your project and adapted your example to reproduce the error: https://github.com/Panimaster/expandable_page_view

How to reproduce the error:

  1. First swipe from the first carousel item to the last one
  2. Swipe back to the first carousel item
  3. Click on the button to remove the first carousel item
  4. Click on the button to remove the second carousel item
  5. A range error "RangeError (index): Invalid value: Only valid value is 0: 1" is thrown.
Limbou commented 2 years ago

Hi @Panimaster, thank you for that great explanation. I believe I was able to pinpoint the problem and it should be fixed in 1.0.15 with #41. Closing this issue for now, if the problem persists please let me know.