0

Problem: CupertinoTabScaffold tab content does not refresh after closing new screen from CupertinoPageRoute

App: There is a list of data in a Listview. I open one data set and remove the favourite status (checked=false). I close the data set and the listview should refresh (FutureBuilder to an SQL database).

Details: I've got a Flutter App with two layouts (Material and Cupertino). In each layout i have four tabs and the content widgets are the same. On the Cupertino App every tab consists of a CupertinoPageScaffold. When i press on an element it navigates to a new screen with CupertinoPageRoute. After closing the CupertinoPageRoute the tab content is not refreshing. The tab content is refreshing when i switch between the four tabs.

If one CupertinoPageRoute is open and i open a new one from here and close it again then the content of the opened CupertinoPageScaffold is refreshing. The data is refreshing without a callback etc., just by calling the future (i think).

Means there should be a problem with the CupertinoTabScaffold. There is no problem on the Material App. The tab contents of the Material App are refreshing when closing a MaterialPageRoute.

Question: Is there a problem at this position? Do you have the same issue or maybe a solution or workaround?

Code: My code is not really representative so i will create a new clean project for you. please confirm if code is necessary.

What i tried: I tried a lot of solutions from the internet like callbacks, setState, .then, .whencomplete for the route. nothing seems to work.

Thank you in advance.

EDIT 03.10.2021: the tabcontroller with SingleTickerProviderStateMixin reloads the open tab when i open or close an new screen. if i just use DefaultTabController Widget than it doesn't. So i have to edit the CupertinoTabController.

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin  {
  late TabController _tabController;
  final CupertinoTabController _cuptabController = CupertinoTabController();

  Future<void> _refreshdata() async {
    downloadJSON1();
    setState(() {
    });
  }

  callback() {
    _refreshdata();
  }

  @override
  void initState() {
    _refreshdata();
    super.initState();
    _tabController = TabController(vsync: this, length: 2, initialIndex: 0);
    _cuptabController.index = widget.starttab;
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

...
}
AlexF1
  • 365
  • 3
  • 13

2 Answers2

0

I can suggest a few options:

Option 1: change your FutureBuilder into a StreamBuilder. FutureBuilder does not refresh automatically when you save the data which StreamBuilder does very well.

Option 2: Use a setState but not on the context of the route you are closing, but rather on the context of the original page you want to refreh

setState(() {  });
Canada2000
  • 1,688
  • 6
  • 14
  • same behavior as before; means no refresh – AlexF1 Oct 01 '21 at 13:07
  • i am developing two small dummy apps with saving and showing favorite dataset, one app with material and one with cupertino layout. a live example should be better to test and analyze with. i will try uploading a gif/video of app behavior, too. – AlexF1 Oct 01 '21 at 13:11
  • Did you try to change FutureBuilder into StreamBuiler? It must work and it is a quick change – Canada2000 Oct 02 '21 at 01:46
  • Yes i changed it into Streambuilder, it works like before on Android, but no improvement on CupertinoApp. At the moment i'm dev a new empty app, but it doesn't seem to work on android too. :-) - I have to recreate it. – AlexF1 Oct 03 '21 at 07:59
0

for the moment i solved it with a .then-callback from PageRoute. i just passed the callback to the deepest Widget/PageRoute. But if you have a solution/idea for the tabcontroller would be great.

Souce: how to refresh state on Navigator.Pop or Push in flutter

      Navigator.push(context,
      CupertinoPageRoute(
        builder: (BuildContext context) => MyWidget(
          'myparameters'),),).then((value) => setState(() {callback();}));
AlexF1
  • 365
  • 3
  • 13