Flutter
System Requirements
For Android:
minimum Android API level: 26 or higher
minimum Kotlin version: 1.9.10 or higher
For iOS:
minimum iOS version: 15.0 or higher
minimum Xcode version: 15.0 or higher
minimum Swift version: 5.9 or higher
Step 1. Install Nativebrik Bridge SDK to your app
Nativebrik Bridge SDK is available through https://pub.dev/packages/nativebrik_bridge.
Add the following to your pubspec.yaml
file:
dependencies:
nativebrik_bridge: ^0.4.0
Run the following command to install the package:
flutter pub get
or install the SDK via flutter pub add
flutter pub add nativebrik_bridge
Step 2. Initialize Nativebrik Bridge SDK in your composable app
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.
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 {
defaultConfig {
// Set the minimum sdk version to 26
minSdkVersion 26
}
}
finally, set the kotlin version to >= 1.9.10 in your settings.gradle file.
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
to15.0
Once you're finished, you can start using Nativebrik.
Last updated