import 'dart:ffi';

import 'package:dali_toolkit_flutter/gen/generated_bindings.dart';
import 'package:flutter/material.dart';

DynamicLibrary daliLib = DynamicLibrary.open('libDali.Toolkit.so');

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: Main(),
        ),
      ),
    );
  }
}

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

  @override
  State<Main> createState() => _MainState();
}

class _MainState extends State<Main> {
  final NativeLibrary nativeLibrary = NativeLibrary(daliLib);

  @override
  Widget build(BuildContext context) {
    final point =
        nativeLibrary.DALI_ToolKit_DaliStrokePoint_Create(200, 400, nullptr);

    final coordX =
        nativeLibrary.DALI_ToolKit_DaliStrokePoint_X_Get(point, nullptr);
    final coordY =
        nativeLibrary.DALI_ToolKit_DaliStrokePoint_Y_Get(point, nullptr);
    final pressure =
        nativeLibrary.DALI_ToolKit_DaliStrokePoint_P_Get(point, nullptr);

    nativeLibrary.DALI_ToolKit_DaliStrokePoint_Destroy(point);

    return Text('DaliStrokePoint! X=$coordX, Y=$coordY, P=$pressure');
  }
}
