Flutter

This code is an implementation reference for using the Graph API with flutter.

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

void main() => runApp(const MaterialApp(home: WebViewExample()));

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

  @override
  State<WebViewExample> createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  late final WebViewController _controller;

  @override
  void initState() {
    super.initState();

    late final PlatformWebViewControllerCreationParams params;
    params = const PlatformWebViewControllerCreationParams();
    final WebViewController controller =
        WebViewController.fromPlatformCreationParams(params);

    controller
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..addJavaScriptChannel(
        'Value',
        //Name of the channel the HTML chart template posts to - keep as this.
        onMessageReceived: (JavaScriptMessage message) {
          print("Value from the chart=\"${message.message}\"");
        },
      )
      ..loadRequest(
          Uri.parse('https://api.tryterra.co/v2/graphs/test?type=SLEEP_REM_SUMMARY'));

    _controller = controller;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.purple,
      appBar: AppBar(
        title: const Text('Flutter WebView example'),
        actions: const <Widget>[],
      ),
      body: WebViewWidget(controller: _controller),
    );
  }
}

Example graph: