Flutter
サポート環境
Android
Android API level: 26 以上
Kotlin: 1.9.10 以上
iOS
iOS 15.0 以上
Xcode 15.0 以上
Swift 5.9 以上
Step 1. パッケージをインストールする
https://pub.dev/packages/nativebrik_bridge にパッケージが公開されています。
以下のコマンドを実行してパッケージをインストールしてください。
flutter pub add nativebrik_bridgeまたは、直接pubspec.yamlを編集し、pub getを実行することでもインストールできます。
dependencies:
nativebrik_bridge: ^0.10.6flutter pub getStep 2. Nativebrik SDKを初期化する
import 'package:nativebrik_bridge/nativebrik_bridge.dart';
import 'package:nativebrik_bridge/provider.dart';
import 'package:nativebrik_bridge/user.dart';
// ...
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Nativebrik Client
NativebrikBridge("<PROJECT_ID>");
// Run your app
runApp(const MyApp());
}
class _YourAppState extends State<YourApp> {
@override
void initState() {
if (!mounted) return;
// Set user's properties to use them in the nativebrik experiment
final user = NativebrikUser();
await user.setProperties({
'prefecture': "Tokyo",
'environment': const bool.fromEnvironment('dart.vm.product')
? 'production'
: 'development',
});
}
@override
Widget build(BuildContext context) {
// 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
}Step 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 DeploymentsChange the
minimum deploymentsto15.0
Once you're finished, you can start using Nativebrik.
Last updated