InjectedTabPageView class Null safety

Inject a TabController and PageController and sync them to work together to get the most benefit of them.

This injected state abstracts the best practices to come out with a simple, clean, and testable approach to control tab and page views.

If you don't use OnTabPageViewBuilder to listen the state, it is highly recommended to manually dispose the state using Injected.dispose method.

Example: of controlling TabBarView, PageView, and TabBar with the same InjectedTabPageView

 final injectedTab = RM.injectTabPageView(
   initialIndex: 2,
   length: 5,
 );

 //In the widget tree;
 @override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       appBar: AppBar(
         title: OnTabViewBuilder(
           listenTo: injectedTab,
           builder: (index) => Text('$index'),
         ),
       ),
       body: Column(
         children: [
           Expanded(
             child: OnTabViewBuilder(
               builder: (index) {
                 print(index);
                 return TabBarView(
                   controller: injectedTab.tabController,
                   children: views,
                 );
               },
             ),
           ),
           Expanded(
             child: OnTabViewBuilder(
               builder: (index) {
                 return PageView(
                   controller: injectedTab.pageController,
                   children: pages,
                 );
               },
             ),
           )
         ],
       ),
       bottomNavigationBar: OnTabPageViewBuilder(
          listenTo: injectedTab,
          builder: (index) => BottomNavigationBar(
            currentIndex: index,
            onTap: (int index) {
              injectedTab.index = index;
            },
            selectedItemColor: Colors.blue,
            unselectedItemColor: Colors.blue[100],
            items: tabs
                .map(
                  (e) => BottomNavigationBarItem(
                    icon: e,
                    label: '$index',
                  ),
                )
                .toList(),
          ),
      ),
   );
 }

Constructors

InjectedTabPageView()

Properties

autoDisposeWhenNotUsed bool
read-only, inherited
error → dynamic
The error
read-only, inherited
hasData bool
The state is mutated successfully.
read-only, inherited
hasError bool
The stats has error
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
hasObservers bool
Whether the state has observers
read-only, inherited
index int
The index of the currently selected tab. [...]
read / write
indexIsChanging bool
True while we're animating from previousIndex to index as a consequence of calling animateTo.
read-only
isActive bool
Whether the state is active or not. [...]
read-only, inherited
isDone bool
The state is mutated using a stream and the stream is done.
read-only, inherited
isIdle bool
The state is initialized and never mutated.
read-only, inherited
isWaiting bool
The state is waiting for and asynchronous task to end.
read-only, inherited
length int
The number of tabs / pages. It can set dynamically [...]
read / write
oldSnapState SnapState<int>
read-only, inherited
pageController PageController
Get the associated PageController
read-only
previousIndex int
The index of the previously selected tab.
read-only
rebuild → _RebuildTab
Listen to the InjectedTabPageView and rebuild when tab index is changed.
late, final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
snapState SnapState<int>
A snap representation of the state
read / write, inherited
state int
read-only, inherited
stateAsync Future<int>
It is a future of the state. The future is active if the state is on the isWaiting status.
read-only, inherited
tabController TabController
Get the associated TabController
read-only

Methods

animateTo(int value, {Duration duration = kTabScrollDuration, Curve curve = Curves.ease}) → void
Immediately sets index and previousIndex and then plays the animation from its current value to index.
dispose() → void
Dispose the state.
inherited
initializeState() FutureOr<int>
Initialize the state
inherited
nextView() Future<void>
Animates the controlled pages/tabs to the next page/tab. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notify() → void
Notify observers
inherited
onAll<R>({R onIdle()?, required R onWaiting()?, required R onError(dynamic error, VoidCallback refreshError)?, required R onData(int data)}) → R
inherited
onOrElse<R>({R onIdle()?, R onWaiting()?, R onError(dynamic error, VoidCallback refreshError)?, R onData(int data)?, required R orElse(int data)}) → R
inherited
previousView() Future<void>
Animates the controlled pages/tabs to the previous page/tab. [...]
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited