initializeM4eSDK function
Initializes the m4e sdk with specified SDKConfig env
Example initialization:
Note: before initializing m4eSDK, you should call WidgetsFlutterBinding.ensureInitialized()
method
as of flutter --version 1.12
to ensure that your application has been properly
initialized before initializing the m4eSDK
This should be initialized in the entrance level
of the application ie main.dart
before runApp
method is called.
import 'package:m4edart/m4e_sdk_initialize.dart' as sdk;
void main() {
WidgetsFlutterBinding.ensureInitialized();
sdk.initializeM4eSDK(config: SDKConfig(...));
runApp(...)
}
Implementation
void initializeM4eSDK({@required SDKConfig config}) {
//! services
m4eSDK.registerLazySingleton(
() => M4eAuth(authApi: m4eSDK(), connectionChecker: m4eSDK()));
m4eSDK.registerLazySingleton(() =>
M4eTransaction(transactionApi: m4eSDK(), connectionChecker: m4eSDK()));
m4eSDK.registerLazySingleton(
() => M4eWallet(walletApi: m4eSDK(), connectionChecker: m4eSDK()));
//! APIS
m4eSDK.registerLazySingleton<AuthApi>(() => AuthApiImpl(
client: m4eSDK(), storage: m4eSDK(), loggingInterceptor: m4eSDK()));
m4eSDK.registerLazySingleton<TransactionApi>(
() => TransactionApiImpl(
client: m4eSDK(),
loggingInterceptor: m4eSDK(),
headerInterceptor: m4eSDK(),
),
);
m4eSDK.registerLazySingleton<WalletApi>(
() => WalletApiImpl(
client: m4eSDK(),
loggingInterceptor: m4eSDK(),
headerInterceptor: m4eSDK(),
),
);
// //! request interceptors
m4eSDK.registerLazySingleton(() => M4eLoggingInterceptors());
m4eSDK.registerLazySingleton(
() => M4eHeaderInterceptors(dio: m4eSDK(), authApi: m4eSDK()));
//! external dependencies
// data connection checker
m4eSDK.registerLazySingleton(() => DataConnectionChecker());
// local storage
m4eSDK.registerLazySingleton(() => FlutterSecureStorage());
// http client (dio)
BaseOptions _options = BaseOptions(
baseUrl: config.baseUrl,
connectTimeout: ClientRequest.kConnectionTimeout,
receiveTimeout: ClientRequest.kRecieveTimeout,
);
m4eSDK.registerLazySingleton(() => Dio(_options));
}