BaseCubitPage<C extends MainCubit<MainBlocState>> class abstract

A base class for all stateless widget pages in the application that use a Cubit.

This class extends BasePageStatelessDelegate and provides a foundation for creating stateless widget pages that are associated with a specific Cubit.

Type Parameters:

  • C: The type of Cubit this page will use. Must extend MainCubit.

Features:

  • Built-in loading state management via CommonBloc
  • Automatic dependency injection using GetIt
  • Navigation support via AppNavigator
  • Built-in loading overlay with timeout
  • Direct state management without events

The class manages:

  • Loading indicator display and hiding
  • Common bloc integration
  • Navigation setup
  • Dependency injection

Usage example:

class MyCounterPage extends BaseCubitPage<CounterCubit> {
  const MyCounterPage({super.key});

  @override
  Widget buildPage(BuildContext context) {
    return buildLoadingOverlay(
      child: Scaffold(
        appBar: AppBar(title: const Text('Counter')),
        body: BlocBuilder<CounterCubit, CounterState>(
          builder: (context, state) {
            return Text('${state.count}');
          },
        ),
        floatingActionButton: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            FloatingActionButton(
              onPressed: () => cubit.increment(), // Direct method call
              child: const Icon(Icons.add),
            ),
            const SizedBox(height: 16),
            FloatingActionButton(
              onPressed: () => cubit.decrement(), // Direct method call
              child: const Icon(Icons.remove),
            ),
          ],
        ),
      ),
    );
  }
}

Compared to BaseBlocPage, this class:

  1. Uses direct method calls instead of events
  2. Generally requires less boilerplate code
  3. Is better suited for simple state changes
  4. Still provides all the same infrastructure for loading states and error handling
Inheritance

Constructors

BaseCubitPage({Key? key})

Properties

commonBloc CommonBloc
latefinalinherited
cubit → C
Access the stateManager as a Cubit with the correct type.
no setter
di GetIt
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateManager → C
The state manager instance for this page (could be a Bloc or Cubit), automatically initialized with dependencies.
latefinalinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
inherited
buildLoadingOverlay({required Widget child, String? loadingKey = LoadingKey.global, Widget? loadingWidget, Duration timeout = const Duration(seconds: 30)}) Widget
override
buildPage(BuildContext context) Widget
Builds the main content of the page.
inherited
buildPageListeners({required Widget child}) Widget
Builds any additional bloc listeners.
override
buildPageLoading() Widget
Builds the loading indicator widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
hideLoading({String? key = LoadingKey.global}) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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