Step 2. Initialize Nativebrik Bridge SDK in your composable app
main.dart
import 'package:nativebrik_bridge/nativebrik_bridge.dart';
import 'package:nativebrik_bridge/provider.dart';
import 'package:nativebrik_bridge/user.dart';
// ...
class _YourAppState extends State<YourApp> {
// 1. Initialize Nativebrik Bridge SDK
final nativebrik = NativebrikBridge("<YOUR_NATIVEBRIK_PROJECT_ID>");
@override
void initState() {
if (!mounted) return;
// 2. Set user's properties to use them in the nativebrik experiment.
// Setting other properties such as email, name unleash the full power of nativebrik.
final user = NativebrikUser();
await user.setProperties({
'environment': const bool.fromEnvironment('dart.vm.product')
? 'production'
: 'development',
});
}
@override
Widget build(BuildContext context) {
// 3. Add NativebrikProvider to your root widget:
return NativebrikProvider(
child: MaterialApp(
// ...
),
);
}
}
Step 3.a (Android only) Set up Platform Specific Code
To get it working on Android, you need to make a small change to your MainActivity.kt file.
MainActivity.kt
package com.example.app
import io.flutter.embedding.android.FlutterFragmentActivity
// 1. Extend FlutterFragmentActivity instead of FlutterActivity
class MainActivity: FlutterFragmentActivity()
and, set the minimum android sdk version to 26 in your android/app/build.gradle file.
android/app/build.gradle
android {
defaultConfig {
// Set the minimum sdk version to 26
minSdkVersion 26
}
}
finally, set the kotlin version to >= 1.9.10 in your settings.gradle file.
settings.gradle
plugins {
// ...
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}
3.b. (iOS only) Set up Platform Specific Code
To get it working on iOS, you need to change a minimum deployments to 15.0 in your ios/Runner.xcodeproj/project.pbxproj file.
In Xcode, navigate to Runner.xcodeproj > TARGETS > Runner > General > Minimum Deployments
Change the minimum deployments to 15.0
Once you're finished, you can start using Nativebrik.