I have a one MainExerseClass dart class. In which I have ImageSequenceAnimator and LinearPercentIndicator which should be restarted when control comes to the MainExerseClass dart by poping another class. The count1 is getting updated but ImageSequenceAnimator not getting updated. Below is the code.
class MainExerseClass extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return Exersise();
}
}
class Exersise extends State<MainExerseClass> with WidgetsBindingObserver{
var count1;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
//do your stuff
_requestSqlData();
}
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void initState() {
// TODO: implement initState
//count1 = widget.progress;
_requestSqlData();
super.initState();
}
void _requestSqlData() {
_requestSqlDataAsync();
}
void _requestSqlDataAsync() async {
int i = await DatabaseHelper.instance.getDayExcCounter("Day 1");
setState(() {
count1 = i;
});
print(count1);
}
void _gotoB() async {
String parameter = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => Resttimer(ExcerciselistPojo.randomList[count1].name,count1.toString())),
);
setState(() {
count1 = int.tryParse(parameter);
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
SizeConfig().init(context);
return Scaffold(
body: new Column(
children: <Widget>[
new Row(
children: <Widget>[
Builder(
builder: (context) => IconButton(
icon: Icon(Icons.arrow_back),
iconSize: 30,
onPressed: () {
// Here i want context
if (Navigator.canPop(context)) {
Navigator.pop(context);
} else {
SystemNavigator.pop();
}
},
),
),
new Container(
margin: const EdgeInsets.fromLTRB(20, 0, 0, 0),
child: new Text("Exercise",
style: new TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold)))
],
),
new Container(
margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: IntervalProgressBar(
direction: IntervalProgressDirection.horizontal,
max: ExcerciselistPojo.randomList.length,
progress: count1,
intervalSize: 2,
size: Size(600, 10),
highlightColor: Colors.pink,
defaultColor: Colors.grey,
intervalColor: Colors.transparent,
intervalHighlightColor: Colors.transparent,
reverse: false,
radius: 0)),
new Container(
margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Container(
height: 30,
alignment: Alignment.centerLeft,
child: FlatButton(
child: Image.asset("assets/images/play.webp"),
onPressed: () async {
//_updatecountertodb();
count1--;
if(count1<0)
count1=0;
await DatabaseHelper.instance.insertExcCounter("Day 1", count1);
_gotoB();
},
),
),
new Container(
height: 30,
alignment: Alignment.centerRight,
child: FlatButton(
child: Image.asset("assets/images/play.webp"),
onPressed: () async {
//_updatecountertodb();
count1++;
if(count1>5)
count1=0;
await DatabaseHelper.instance.insertExcCounter("Day 1", count1);
_gotoB();
},
),
)
],
),
),
new Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: new ImageSequenceAnimator(
"assets/images/" + ExcerciselistPojo.randomList[count1].imageUrl,
"Pic_",
0,
5,
"webp",
3,
isAutoPlay: true,
color: null,
fps: 2,
isLooping: true,
),
height: 300,
),
new Container(
margin: EdgeInsets.fromLTRB(0, 0, 5, 0),
alignment: Alignment.centerRight,
child: IconButton(
icon: Image.asset("assets/images/rest_time_exc.png"),
onPressed: () {},
),
),
new Container(
margin: EdgeInsets.fromLTRB(10, SizeConfig.screenHeight /16, 0, 0),
alignment: Alignment.centerLeft,
child: new Text(ExcerciselistPojo.randomList[count1].name,
style: new TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.blueGrey)),
),
new Container(
margin: EdgeInsets.fromLTRB(0, SizeConfig.screenHeight /44, 0, 0),
child: new LinearPercentIndicator(
animation: true,
animationDuration: 6000,
lineHeight: SizeConfig.screenHeight / 10,
percent: 1,
center: Text("100/68%"),
linearStrokeCap: LinearStrokeCap.butt,
progressColor: Colors.pink,
),
)
],
));
}
}
I am navigating from the second class to MainExerseClass dart by using
onTap: () {
Navigator.pop(context, count);
},
in MainExerseClass count is getting updated but ImageSequenceAnimator not refreshed it is showing old animation. And i want to restart LinearPercentIndicator.