How to use

graph
loading[LoadingWidget]
failure[FailureWidget]
child[ChildWidget]
bloc[Bloc extends BaseBloc]
repository[Repository]
interceptor[json decoder interceptor && token interceptor]
localDataSource[LocalDataSource]
remoteDataSource[RemoteDataSource]
bloc --futureWrapper ----> repository
bloc --helperBloc.isLoading--> loading
bloc --helperBloc.hasFailure--> failure
bloc --result of futureWrapper is success --> child
repository --> localDataSource
localDataSource --> database
repository --> remoteDataSource
remoteDataSource --> interceptor
interceptor --> server

  • Create LocalDataSource for your app and make it depends on BaseLocalDataSource (it’s recommended to read BaseLocalDataSource section).

  • Create RemoteDataSource for your app and extends from BaseRemoteDataSource (it’s recommended to read BaseRemoteDataSource section).

  • Create SharedPrefDataSource for your app and extends from BaseSharedPreferences.

  • Add TokenInterceptor to take advantage of token management .

  • Add JsonDecoderInterceptor to take advantage of decoding json inside interceptors.

  • Create your repository and make it extends from BaseRepositiory, then start using ** requestData** function for your datasource calls (it’s recommended to read BaseRepositiory section).

  • If you are using Bloc as statemangement then create a sub class for BaseBlocPageState and override required functions.

  • For every bloc you create extend BaseBloc this will give you helper functions to fast the development process (it’s recommended to read Statemangment section).

Folder Structure

- lib

	|---- datasource
	|		|
	|		|--- local_data_soruce
	|		|		|
	|		|		|-- i_base_local_data_source.dart
	|		|		|
	|		|		|-- base_local_data_source.dart
	|		|		|
	|		|--- remote_data_source
	|		|		|
	|		|		|-- i_base_remote_data_source.dart
	|		|		|
	|		|		|-- base_remote_data_source.dart
	|		|		|
	|		|--- shared_preferences_data_source
	|		|		|
	|		|		|-- i_base_shared_preferences.dart
	|		|		|
	|		|		|-- base_shared_preferences.dart
	|		|
	|---- repository
	|		|
	|		|--- base_repository.dart
	|		|
	|		|--- common_app_repository.dart
	|
	|---- presentation
	|		|
	|		|--- mixins
	|		|		|
	|		|		|-- bloc_builder_mixin.dart
	|		|		|
	|		|		|-- bloc_consumer_mixin.dart
	|		|		|
	|		|		|-- bloc_listener_mixin.dart
	|		|		|
	|		|		|-- bloc_provider_mixin.dart
	|		|		|
	|		|		|-- search_mixin.dart
	|		|		|
	|		|		|-- size_mixin.dart
	|		|		|
	|		|		|-- theme_mixin.dart
	|		|
	|		|--- widgets
	|		|		|
	|		|		|-- base_bloc_page.dart
	|		|		|
	|		|		|-- base_state_widget.dart
	|		|		|
	|		|		|-- bloc_helper_widget.dart
	|		|		|
	|		|		|-- bloc_state_getit.dart
	|		|		|
	|		|		|-- bloc_state_provider.dart
	|		|
	|---- state_mangement
	|		|
	|		|--- bloc_state_mangement
	|		|		|
	|		|		|-- base_bloc.dart
	|		|		|
	|		|		|--- helper_bloc
	|		|		|
	|		|		|	|-- helper_bloc.dart
	|		|		|	|
	|		|		|	|-- helper_state.dart
	|		|		|	|
	|		|		|	|-- helper_event.dart
	|		|
	|---- utils
	|		|
	|		|--- data_model_wrapper.dart
	|		|
	|		|--- token_constants.dart
	|		|
	|		|--- extensions
	|		|		|
	|		|		|-- double_ext.dart
	|		|		|
	|		|		|-- int_ext.dart
	|		|		|
	|		|		|-- map_ext.dart
	|		|		|
	|		|		|-- string_ext.dart
	|		|
	|		|--- failures
	|		|		|
	|		|		|-- base_failure.dart
	|		|		|
	|		|		|-- local_failures.dart
	|		|		|
	|		|		|-- network_failures.dart
	|		|
	|		|--- interceptors
	|		|		|
	|		|		|-- json_decoder_interceptor.dart
	|		|		|
	|		|		|-- token_interceptor.dart
	|		|
	|---- constant.dart
	|
	|---- type_defs.dart

Data

  1. Failures:

    • BaseFailure:

      Base failure class which every failure must implement, has one property to override which is failureMessage


      Datasource
      • BaseRemoteDataSource:

        • Deserializer

          T Function(Object?) how to parse the json to an object.

        • Future<DataModelWrapper> request

          This function will make the Http request, parse the response and return DataModelWrapper based on http response.

        • failureParser(Response response)

          Return failure String base on response.

        • defaultErrorMessage

          The default message inside failures, if couldn’t failureParser return null.

        • wrapBodyWithBaseRequest(data)

          wrap requsted body with base request.


        Repository

        graph LR
        A[Repository] --1- localCall --> B[LocalDataSource]
        A --2- remoteCall --> C[RemoteDataSource]
        C --3- data--> A
        A --4- saveRemoteDataFunction--> B
        

        • BaseRepository:

          • Future<DataModelWrapper> requestData

            This function will wrap calls going to datasource layer, and will manage getting the data either from remote server or local data base, and caching the result in localdatabase.

        Statemangment

        • HelperBloc

          This bloc will provide three main functionallty: 1- PageLoading. 2- ErrorHandling. 3- Providing BuildContext to your bloc.

        • BaseBloc:

          void runFunctionWithContext(ContextCallback contextCallback) This function will provide BuildContext.

          Future<DataModelWrapper> futureWrapper : this function will wrap your future call and manage the page loading and displaying error message.

        Presentation

        • Mixins

          • SizeMixin:

            Will provide main size property for your state class.

          • ThemeMixin:

            Will provide main theme property for your state class.

          • SearchMixin:

            Will provide main search functionallty for your state class.

          • BlocProvidersMixin:

            Will inject a BlocProvider above your state class.

          • BlocListenerMixin:

            Will inject a BlocListener above your state class.

          • BlocConsumerMixin:

            Will inject a BlocConsumer above your state class.

          • BlocBuilderMixin:

            Will inject a BlocBuilder above your state class.


          Interceptors
          • TokenInterceptor

            Helper interceptor to inject the authentication token in the request.

          • JsonDecoderInterceptor

            Helper interceptor to convert the json from String to Map<String, dyanmic>

          GitHub

          View Github