flutter_sklearn_plugin 0.0.3 flutter_sklearn_plugin: ^0.0.3 copied to clipboard
A new Flutter project.
import 'dart:math';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_sklearn_plugin/flutter_sklearn_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
var _tone ='-1';
final sklearnModel = FlutterSklearnPlugin();
@override
void initState() {
super.initState();
sklearnModel.prepareSklearnModel();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await FlutterSklearnPlugin.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
void predict(){
// String tone = await sklearnModel.sklearnModelPredict(features: <double>[-0.30887250000000005, -0.01823033333333331, 0.5271035 ,0.550573485429057 ,0.5799306455419188 ,0.900827707563383]).toString();
// print('tone:'+tone);
Future future = sklearnModel.sklearnModelPredict(features: <double>[-0.30887250000000005, -0.01823033333333331, 0.5271035 ,0.550573485429057 ,0.5799306455419188 ,0.900827707563383]);
future.then((value) => setState(() {
_tone = value;
}));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Row(
children: [
Text('Running on: $_platformVersion\n'),
ElevatedButton(onPressed: predict, child: Text('$_tone')),
],
),
),
),
);
}
}