terra_flutter_bridge 2.2.1
terra_flutter_bridge: ^2.2.1 copied to clipboard
Terra's health SDK for Flutter, over the same generated bridge as the React Native package.
terra_flutter_bridge #
Terra's health SDK for Flutter: Apple Health on iOS, Health Connect (and optionally Samsung Health)
on Android. The Dart API is the React Native package's, over the same generated bridge
(hybrid-common), so both wrappers answer every op and stream the same way.
Requires Flutter 3.24 or later, iOS 15, and Android API 28 with Kotlin 2.0 or later and Android Gradle Plugin 8.9.1 or later (the floor of Health Connect's client library).
Host setup #
The native client is built at app launch, before any Dart runs, because a background sync wake never starts a Flutter engine. Each platform needs a few lines of native configuration.
iOS #
-
TerraDevIDinInfo.plist, plusNSHealthShareUsageDescription(andNSHealthUpdateUsageDescriptionif you write). -
The HealthKit capability with background delivery,
fetchinUIBackgroundModes, andco.tryterra.sdk.refreshinBGTaskSchedulerPermittedIdentifiers. -
One line in
application(_:didFinishLaunchingWithOptions:), beforesuper:import terra_flutter_bridge TerraFlutterBridgePlugin.bootstrap()
Android #
-
The developer id in
AndroidManifest.xml's<application>; the package's startup initializer reads it beforeApplication.onCreate:<meta-data android:name="co.tryterra.sdk.DEV_ID" android:value="YOUR_DEV_ID" /> -
MainActivityextendsFlutterFragmentActivity, notFlutterActivity: the Health Connect permission sheet is launched through an activity result, which only aComponentActivitycan register for. With a plainFlutterActivity,permissions.requestanswersbridge.no_activityand the plugin logs why. -
minSdk = 28, and the Health Connect permissions your requests expand to, plus theVIEW_PERMISSION_USAGEactivity alias Android 14 requires.example/androidhas both. -
Samsung Health is opt-in:
terraSamsungHealth=trueinandroid/gradle.properties, and Samsung'ssamsung-health-data-api.aarin your app, which no Terra artifact may carry.
A host that removed WorkManager's default initializer calls TerraFlutter.bootstrap(this) at the
end of Application.onCreate instead of relying on the startup initializer.
Use #
WidgetsFlutterBinding.ensureInitialized();
final terra = createTerra(tokenProvider: fetchTokenFromYourBackend);
await terra.permissions.request(read: [DataCategory.daily]);
await terra.connect(Source.health, const EndUser.reference(id: 'user-123'));
final steps = await terra.daily.steps(const TimeRange.today());
example/ exercises connect, sync status, reads and a stream on both platforms, and its
integration_test/ drives the plugin on a simulator or emulator.