InjectedTabPageView class abstract

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(),
          ),
      ),
   );
 }
Implemented types
Implementers
Available Extensions

Constructors

InjectedTabPageView()

Properties

customStatus Object?
Custom status of the state. Set manually to mark the state with a particular tag to be used in your logic.
getter/setter pairinherited
error → dynamic
The error
no setterinherited
hasData bool
The state is mutated successfully.
no setterinherited
hasError bool
The stats has error
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
hasObservers bool
Whether the state has listeners or not
no setterinherited
index int
The index of the currently selected tab.
getter/setter pair
indexIsChanging bool
True while we're animating from previousIndex to index as a consequence of calling animateTo.
no setter
isDone bool
The state is mutated using a stream and the stream is done.
no setterinherited
isIdle bool
The state is initialized and never mutated.
no setterinherited
isWaiting bool
The state is waiting for and asynchronous task to end.
no setterinherited
length int
The number of tabs / pages. It can set dynamically
getter/setter pair
pageController PageController
Get the associated PageController
no setter
previousIndex int
The index of the previously selected tab.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapState SnapState<int>
A snap representation of the state
no setterinherited
tabController TabController
Get the associated TabController
no setter

Methods

addCleaner(VoidCallback listener) VoidCallback
Add a callback to be executed when the state is disposed of.
inherited
addObserver({required ObserveReactiveModel listener, bool shouldAutoClean = false, bool isSideEffects = true}) VoidCallback
Add observer to this state.
inherited
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.
cleanState() → void
Clean the state
inherited
dispose() → void
Dispose the state
inherited
nextView() Future<void>
Animates the controlled pages/tabs to the next page/tab.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify() → void
Notify observers
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