I have this Flutter iOS styled Stopwatch and I would like to keep the stopwatch running while I switch through screens.
I already tried with some setState positioned inside the initState function of my Stopwatch but this didn't work.
I think that it doesn't rebuild the widget when I come back to the Stopwatch screen.
//My builder inside a home_screen.dart file
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
controller: controller,
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
icon: Icon(
Ionicons.getIconData('ios-globe'),
),
title: Text('World Clock'),
),
BottomNavigationBarItem(
icon: Icon(
Ionicons.getIconData('ios-alarm'),
),
title: Text('Alarm'),
),
BottomNavigationBarItem(
icon: Icon(
Ionicons.getIconData('ios-bed'),
),
title: Text('Bedtime'),
),
BottomNavigationBarItem(
icon: Icon(
Ionicons.getIconData('ios-stopwatch'),
),
title: Text('Stopwatch'),
),
BottomNavigationBarItem(
icon: Icon(
Ionicons.getIconData('ios-timer'),
),
title: Text('Timer'),
),
],
),
tabBuilder: (context, i) {
if(i == 3){
final Dependencies dependencies = new Dependencies();
return StopWatch(dependencies: dependencies,);
}else{
return CupertinoTabView(
builder: (context){
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(chooseMiddle(i)),
),
child: Center(
child: Text('Screen $i'),
),
);
},
);
}
},
);
}