keyed_collection_widgets
0.4.4, released 2 years ago by ainkin.com
BottomNavigationBar, IndexedStack, and TabController that use item keys instead of indexes.
WASM-ready
What it does
Provides replacements for BottomNavigationBar, IndexedStack, TabController, TabBar, and TabBarView that use item keys (such as enums) instead of numeric indexes. This eliminates the need for manual index-to-meaning conversions and helps avoid range errors.
AI-written summary of version 0.4.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to use enums or meaningful keys for tabs and navigation stacks instead of magic numbers.
- You need to change the set of tabs or navigation items dynamically without re-creating controllers.
Skip it when
- You strictly require traditional numeric index-based tab and stack handling.
- You are using SingleTickerProviderStateMixin and need to change keys dynamically (TickerProviderStateMixin must be used instead).
Strengths
- Eliminates error-prone index-to-enum conversions.
- Allows mutable tabs and animation durations on controllers without recreation.
- Supports DefaultKeyedTabController for cleaner widget trees.
Weaknesses
- Requires TickerProviderStateMixin instead of SingleTickerProviderStateMixin for controllers that change keys.
- Does not check at compile time that the default controller is present in the tree.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
enum TabEnum { favorites, search }
KeyedStack<TabEnum>(
itemKey: _tab,
children: const {
TabEnum.favorites: Center(child: Text('Favorites')),
TabEnum.search: Center(child: Text('Search')),
},
)