Comments (7)
I seem to have found a similar problem, but one is closed by the author and it is not entirely clear how he solved it.
#42
I would be very happy if you could help me find a way to change the number of elements in the list so that this would not cause problems. (I suppose if the new list has more elements than it was, this should not cause a problem)
from flutter.widgets.
Having the same issue.
from flutter.widgets.
+1
Code Sample
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> titles = [];
ItemScrollController scrollController = ItemScrollController();
@override
void initState() {
super.initState();
while(titles.length<30) {
titles.add('Some Text ${titles.length}');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: ScrollablePositionedList.builder(
itemScrollController: scrollController,
itemBuilder: (context, index) => Container(
alignment: Alignment.bottomCenter,
padding: EdgeInsets.symmetric(vertical: 10),
child: Text(titles[index]),
),
itemCount: titles.length,
)
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
OutlineButton(
child: Text('1.Jump to last item'),
onPressed: () {
scrollController.jumpTo(index: titles.length-1);
},
),
OutlineButton(
child: Text('2.Delete the last item'),
onPressed: () {
titles.removeAt(titles.length-1);
setState(() {
});
},
),
],
)
],
),
),
);
}
}
from flutter.widgets.
@iKrupp
I got it working like follows :
I have a variable _deletedItems
that I use to keep track of the elements that are removed from entityList
. When an element is removed, I just increment _deletedItems
.
When index
becomes equal to entityList.length
and _deletedItems != 0
it means that an element was removed from the list, hence a Container()
is returned.
In my case, the code looks something like this :
....
@override
void didUpdateWidget(CustomStatefulWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.entityList.length > widget.entityList.length) {
// An item was removed/deleted from the list
_deletedItems += 1;
}
entityList = widget.entityList;
}
....
itemBuilder: (BuildContext context, int index) {
if (index <= entityList.length ) {
final entity = entityList[index];
return CustomWidget(..);
} else if (index == entityList.length && _deletedItems == 0) {
final entity = entityList[index];
return CustomWidget(..);
} else {
return Container()
}
},
....
from flutter.widgets.
@vabawen thank you for example! Could you also duplicate it here: #42
from flutter.widgets.
@AurelianTimu this was my first thought - returning the stub to an inaccessible index. (for this, it seems, you do not even need to count the number of deleted elements). However, I tried Offstage instead of a container. I will try the container, however this is still a workaround. It would be better if this were fixed on the side of the plugin
from flutter.widgets.
Correct, you dont need the exact count of deleted items in this case. I am using the count for a different purpose. I forgot to mention it in my comment.
from flutter.widgets.
Related Issues (20)
- VisibilityDetector fires event unexpectedly HOT 1
- [ScrollablePositionedList] Scrollbar unexpected jumping HOT 2
- [scrollable_positioned_list]: add jumpTo method to ScrollOffsetController
- [ScrollablePositionedList] PageStorage cast bug
- [ScrollablePositionedList] with StickyHeader
- Unsupported operation: add
- Twitchy scroll animation
- Inconsistent Expansion Direction of AnimatedContainer in ScrollablePositionedList
- [visibility_detector] Incorrect Visibility info Bug after updating to 4.0.0 or later
- A RenderViewport exceeded its maximum number of layout cycles
- R
- RTL support scrollable_positioned_list HOT 1
- Allow or expose scroll controller to be used outside.
- [visibility_detector] onVisibilityChanged not works when scroll faster HOT 5
- Flutter_simple_treeview: could not configure tree node height
- flutter simple tree: lazy build subtree nodes
- [ScrollablePositionedList] Inactive Package
- [visibility_detector] iOS swipe back - Unexpected visibleFraction behaviour. It is just 1.0 or 0.0.
- Use webview load pie charts on ios platform will show blank page in first load, and changed reloadAfterInit to true have blow error.
- Is the scrollable positioned list still in maintenance
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.widgets.