dtb_link 0.0.5+3 copy "dtb_link: ^0.0.5+3" to clipboard
dtb_link: ^0.0.5+3 copied to clipboard

Dtb link

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:dtb_link/dtb_link.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _dtbLinkPlugin = DtbLink();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      debugPrint("initPlatformState");
      initPlatformState();
    });
    _dtbLinkPlugin.onEvent((onData){
      debugPrint("example.onData: $onData");
    });
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      debugPrint("platformVersion before");
      platformVersion = await _dtbLinkPlugin.getPlatformVersion() ?? 'Unknown platform version';
      debugPrint("platformVersion: $platformVersion");
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('DtbLink example app'),
        ),
        body: Center(
          child: Text('PlatformVersion: $_platformVersion\n'),
        ),
      ),
    );
  }
}