HomeiOS Developmentios - Does eradicating code duplication from CupertinoTabView affect efficiency resulting from...

ios – Does eradicating code duplication from CupertinoTabView affect efficiency resulting from absence of const modifier


I am very new to flutter and dart, and I am constructing a easy IOS/Cupertino cellular app. When making a CupertinoTabBar, I adopted some tutorials and created the tabBuilder like so:

      tabBuilder: (context, index) {
        return swap (index) {
          0 => CupertinoTabView(
              builder: (context) => const CupertinoPageScaffold(
                youngster: AudioPlayerTab(),
              ),
            ),
          1 => CupertinoTabView(
              builder: (context) => const CupertinoPageScaffold(
                youngster: LibraryTab(),
              ),
            ),
          2 => CupertinoTabView(
              builder: (context) => const CupertinoPageScaffold(
                youngster: AudioPlayerTab(),
              ),
            ),
          3 => CupertinoTabView(
              builder: (context) => const CupertinoPageScaffold(
                youngster: AudioPlayerTab(),
              ),
            ),
          _ => throw Exception('Invalid index $index'),
        };

As you possibly can see, there’s a number of code duplication right here, so I assumed I might change that.

So I attempted this, and it really works, however I am involved about efficiency:

        buildTab(widget) => CupertinoTabView(
              builder: (_) => CupertinoPageScaffold(youngster: widget),
            );
        return swap (index) {
          0 => buildTab(const AudioPlayerTab()),
          1 => buildTab(const LibraryTab()),
          2 => buildTab(const LibraryTab()),
          3 => buildTab(const LibraryTab()),
          _ => throw Exception('Invalid index $index'),
        };

I discover this code lots cleaner. Nevertheless, my solely concern is that it won’t be as performant, as a result of I not have a const earlier than the CupertinoPageScaffold (although my IDE really useful I put one in entrance of e.g. AudioPlayerTab, however I do not precisely know why). Is that this much less performant because of the absence of const? What does that const do anyhow? Is it good apply to take away code duplication like this?
Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments