Я добавил список логических значений для управления виджетом CountDown независимо от того, приостановлен он или нет. Вот корректировка вашего кода ниже.
Основной виджет для создания элемента для ListView - это
Widget buildItem(int index) {
return !isPauseList[index]
? Countdown(
seconds: list[index],
build: (BuildContext context, double time) => Text(time.toString()),
interval: Duration(milliseconds: 100),
controller: controller,
onFinished: () {
if (index < isPauseList.length) {
setState(() {
isPauseList[index + 1] = false;
});
}
},
)
: Text(list[index].toString());
}
И полная корректировка вашего кода приведена ниже.
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:timer_count_down/timer_controller.dart';
import 'package:timer_count_down/timer_count_down.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.dark,
home: Ex(),
);
}
}
class Ex extends StatefulWidget {
@override
State<StatefulWidget> createState() => ExpandableListView();
}
class ExpandableListView extends State<Ex> {
final CountdownController controller = CountdownController();
List<int> list = [3, 4, 5, 6];
List<bool> isPauseList = [true, true, true, true];
Timer _timer;
int counter = 3;
void _startTimer() {
setState(() {
this.isPauseList[0] = false;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Container(
height: 500,
width: 200,
child: Column(
children: [
Container(
height: 200,
width: 200,
child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
// return Text(list[index].toString());
return buildItem(index);
},
),
),
RaisedButton(
onPressed: () {
setState(() {
_startTimer();
});
},
),
],
),
),
);
}
Widget buildItem(int index) {
return !isPauseList[index]
? Countdown(
seconds: list[index],
build: (BuildContext context, double time) => Text(time.toString()),
interval: Duration(milliseconds: 100),
controller: controller,
onFinished: () {
if (index < isPauseList.length) {
setState(() {
isPauseList[index + 1] = false;
});
}
},
)
: Text(list[index].toString());
}
}