Reputation: 63
I wanted to replace my countdown with a Text when it is finished. I have made that with a List<bool>
and I think my code is good. But it doesn't work and I don't know why... I have a RenderFlex overflowed by 99966 pixels on the bottom
and the countdownTimer
isn't replace when it is finished. This renderFlex is not in all items but just sometimes, I really don't understand. I have this issue : RangeError (index): Invalid value: Only valid value is 0: 1
. The renderFlex leave when I click on the button of the item which is above.
This is my code :
main.dart
class _HomeState extends State<Home> {
List<Item> savedItems = new List<Item>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
actions: [
IconButton(
icon: Icon(Icons.favorite_border),
onPressed: () => pushToFavorite(context))
],
),
body: ListView.builder(
itemCount: itemData.length,
itemBuilder: (context, index) {
...
CountWidget(itemData[index].countdown, index),
...
}
myWidget.dart
class CountWidget extends StatefulWidget {
final int date;
final int index;
const CountWidget(this.date, this.index);
@override
_CountWidgetState createState() => _CountWidgetState();
}
class _CountWidgetState extends State<CountWidget> {
List<bool> notFinished = List<bool>();
@override
Widget build(BuildContext context) {
notFinished.add(true);
return notFinished.elementAt(widget.index)
? Container(
padding: const EdgeInsets.only(top: 10.0),
child: CountdownTimer(
daysSymbol: new Text("j "),
hoursSymbol: new Text(" : "),
minSymbol: new Text(" : "),
secSymbol: new Text(""),
endTime: widget.date,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
onEnd: () {
setState(() {
notFinished[widget.index] =
notFinished[widget.index] == false;
});
}))
: Container(
padding: const EdgeInsets.only(top: 10.0),
child: Text('It is Finished', style : TextStyle(fontSize: 14),));
}
}
What I get when I launch my code
Upvotes: 1
Views: 176
Reputation: 1666
Try adding shrinkWrap: false,
in ListView.builder()
, Also wrap the all Text()
widget with Flexible()
.
Also, a suggestion that rather than doing notFinished.add(true);
, keep all the add all the values inside a StreamBuilder()
this will not only make the app more readable but also eliminate the need to setState() in onEnd()
.
Upvotes: 1