jb3rndt / PersistentBottomNavBarV2

A highly customizable persistent bottom navigation bar for Flutter
https://pub.dev/packages/persistent_bottom_nav_bar_v2
BSD 3-Clause "New" or "Revised" License
47 stars 48 forks source link

Fix exception when number of tabs changes #157

Closed lukehutch closed 2 months ago

lukehutch commented 2 months ago

If the number of tabs changes, I get this exception:

════════ Exception caught by widgets library ═══════════════════════════════════
The following UnsupportedError was thrown building MediaQuery(MediaQueryData(size: Size(448.0, 949.3), devicePixelRatio: 3.0, textScaler: no scaling, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, systemGestureInsets: EdgeInsets(0.0, 24.0, 0.0, 0.0), alwaysUse24HourFormat: false, accessibleNavigation: false, highContrast: false, onOffSwitchLabels: false, disableAnimations: false, invertColors: false, boldText: false, navigationMode: traditional, gestureSettings: DeviceGestureSettings(touchSlop: 8.0), displayFeatures: [])):
Unsupported operation: Cannot remove from a fixed-length list

The relevant error-causing widget was:
    PersistentTabView PersistentTabView:file:///home/luke/Work/click/click_flutter/lib/pages/screens/widgets/navigation_tabs.dart:191:14

When the exception was thrown, this was the stack:
#0      FixedLengthListMixin.removeRange (dart:_internal/list.dart:71:5)
#1      _TabSwitchingViewState.didUpdateWidget (package:persistent_bottom_nav_bar_v2/components/persistent_tab_view_scaffold.dart:546:22)
persistent_tab_view_scaffold.dart:546
#2      StatefulElement.update (package:flutter/src/widgets/framework.dart:5653:55)
framework.dart:5653
...

This PR fixes this by using a list spread operator to create a modifiable list.