stryder-dev / flutter_platform_widgets

Target the specific design of Material for Android and Cupertino for iOS widgets through a common set of Platform aware widgets
MIT License
1.58k stars 171 forks source link

Multiple widgets used the same GlobalKey - cupertino widget renders multiple time #377

Closed MitkoTschimev closed 1 year ago

MitkoTschimev commented 1 year ago

Hi,

I have a problem that the bodyBuilder widget from the PlatformTabScaffold is getting rendered multiple times when I use a router like beamer or go. The following problem ends in a Multiple widgets used the same GlobalKey exception.

You can see in the picture the result after switching the tabs on android and iOS. Android is working as expected but not iOS.

I found this issue but I don't think it is related.

image

This is the code:

@override
  Widget build(BuildContext context) {
    return PlatformTabScaffold(
      iosContentPadding: true,
      bodyBuilder: (context, index) => IndexedStack(
        index: _currentIndex,
        children: [
          // use Beamer widgets as children
          Beamer(
            routerDelegate: _routerDelegates[0],
          ),
          Beamer(
            routerDelegate: _routerDelegates[1],
          ),
        ],
      ),
      tabController: tabController,
      appBarBuilder: (_, index) => PlatformAppBar(
        title: Text("${tabs[index].label}"),
        cupertino: (_, __) => CupertinoNavigationBarData(
          title: Text("${tabs[index].label}"),
          //   only required if useCupertinoTabView = false,
          transitionBetweenRoutes: false,
        ),
      ),
      items: tabs,
    );
  }

When I inspect there is also a difference where the tab bar belongs and I guess thats the issue:

image
MitkoTschimev commented 1 year ago

Ok just figured out that the Cupertino widget is just working different....

For those who have the same problem ->

@override
  Widget build(BuildContext context) {
    return PlatformTabScaffold(
      iosContentPadding: true,
      material: (context, platform) => MaterialTabScaffoldData(
        bodyBuilder: (context, index) => IndexedStack(
          index: _currentIndex,
          children: [
            Beamer(
              routerDelegate: _routerDelegates[0],
            ),
            Beamer(
              routerDelegate: _routerDelegates[1],
            ),
          ],
        ),
      ),
      cupertino: (_, __) => CupertinoTabScaffoldData(
        bodyBuilder: (context, index) => Beamer(
          routerDelegate: _routerDelegates[index],
        ),
      ),
      tabController: tabController,
      appBarBuilder: (_, index) => PlatformAppBar(
        title: Text("${tabs[index].label}"),
        cupertino: (_, __) => CupertinoNavigationBarData(
          title: Text("${tabs[index].label}"),
        ),
      ),
      items: tabs,
    );
  }