sod_core 1.0.1
sod_core: ^1.0.1 copied to clipboard
Core SDK package for SOD application
sod_core #
The core foundation SDK package for the SOD application platform. It provides host configuration, user initialization, custom localization caching, and shared service utilities.
Features #
- Host & Tenant Configuration: Direct initialization (
CoreConfig) or remote fetching (setupHostFromNetwork). - Core SDK Lifecycle: Initialize, configure, and reset SDK state (
CoreSDK). - Custom Localization: Fast network-based localization with persistent caching using stale-while-revalidate (
CachedAssetLoaderNetwork). - Flavors: Integrated support for various platform and client flavors.
Installation #
Add sod_core as a dependency in your pubspec.yaml:
dependencies:
sod_core:
path: path/to/sdk/sod_core
Then run:
flutter pub get
Getting Started & Usage #
1. Configure the Host #
You can configure the SDK using either a local static configuration or by fetching it from a remote network service.
Local Configuration:
import 'package:sod_core/sod_core.dart';
void main() {
final config = CoreConfig(
tenantId: 'sod_user',
appIdentifier: 'sod_user_app',
baseUrl: 'https://api.sod.vn',
serverUrl: 'https://web.sod.vn',
appName: 'SOD',
appTitle: 'Super App SOD',
appId: 'your_app_id',
masterKey: 'your_master_key',
clientKey: 'your_client_key',
chatKey: 'your_chat_key',
appIconFolder: 'sod_user',
);
CoreSDK.setupHost(config);
}
Network Configuration:
import 'package:sod_core/sod_core.dart';
Future<void> initializeApp() async {
// Fetches configuration and initializes network assets for localization
await CoreSDK.setupHostFromNetwork(
'https://api.sod.vn/config',
'your_application_key',
);
}
2. Initialize with User Session #
Once configured, initialize the SDK using an active session or external user information:
import 'package:sod_core/sod_core.dart';
Future<void> loginUser() async {
final user = ExternalUser(
id: 'user_12345',
name: 'John Doe',
email: 'john.doe@example.com',
phone: '+84900000000',
token: 'jwt_auth_token_here',
);
await CoreSDK.init(
Di: user,
enableMap: true,
enableAnalytics: true,
);
}
3. Localization Support #
The package ships with CachedAssetLoaderNetwork, which automatically saves network translations to local storage and updates them in the background (SWR pattern) to ensure lightning-fast startup times:
import 'package:sod_core/sod_core.dart';
final translationLoader = CachedAssetLoaderNetwork(
{
'en': 'https://web.sod.vn/assets/assets/lang/en.json',
'vi': 'https://web.sod.vn/assets/assets/lang/vi.json',
},
cacheDuration: const Duration(days: 7),
);
API Reference #
CoreSDK #
| Method / Property | Description |
|---|---|
isHostConfigured |
Checks if the host config has been loaded. |
isInitialized |
Checks if both the host config is set up and the SDK is initialized. |
setupHost(CoreConfig config) |
Synchronously configures the host environment. |
setupHostFromNetwork(String url, String key) |
Fetches configuration from a remote server and sets up localization. |
init({required ExternalUser Di, bool enableMap, bool enableAnalytics}) |
Completes authentication registration and initializes system services. |
initAppSettings(BuildContext context) |
Loads context-dependent application settings. |
reset() |
Clears the host configuration and resets the SDK state. |