If you haven’t already, and you’re developing on iOS, visit the Apple Health docs and follow the “Enable HealthKit” section to configure HealthKit.

Installation

flutter pub add metriport_flutter

You’ll need to ensure that the MetriportSDK pod is installed as well.

cd ios
pod install

If you are using Objective-C for your AppDelegate file you will need to set it up as follows:

#import "AppDelegate.h"
#import "MetriportConfiguration.h" // add this line

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   [MetriportConfiguration checkBackgroundUpdates]; // add this line

   // your code
}

If you are using Swift for your AppDelegate file you will need to set it up as follows:

import Foundation
import UIKit
import MetriportSDK // add this line
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bridge: RCTBridge!
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    MetriportClient.checkBackgroundUpdates() // add this line

    // your code
  }
}

Usage

To use our SDK go to the root of your project and add:

import 'package:flutter/material.dart';
import 'package:metriport_flutter/metriport_flutter.dart';

void main() => runApp(const WebViewExample());

class WebViewExample extends StatelessWidget {
  const WebViewExample({super.key});

  
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Flutter WebView example')),
        body: const Column(
          children: [
            Expanded(
              child: WebView(
                clientApiKey: "CLIENT_API_KEY",
                token: "CONNECT_TOKEN",
                colorMode: "dark",
                customColor: "green",
                sandbox: false,
                providers: ["fitbit", "cronometer"],
              ),
            )
          ],
        ),
      ),
    );
  }
}

Ensure you use your Client Key here, and not your Secret Key. You can read more about the differences between the two in our API Keys guide.

As per the guide, we recommend to store your Client Key in environment secrets, and not commit it in plain text to your repository.

As per the Quickstart guide, you’ll need to generate a token on your server before opening the Connect Widget. You can read more about this here.

Apple Health

For details about receiving Apple Health data via webhooks, see the guide here.