Files
terra/example/lib/main.dart
Developer 194033514f init
2026-05-18 17:58:19 +08:00

131 lines
4.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:terra/terra.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 _terraPlugin = Terra();
@override
void initState() {
super.initState();
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 _terraPlugin.getPlatformVersion() ?? '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;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Running on: $_platformVersion\n'),
ElevatedButton(
onPressed: () async {
var deviceCount = await Terra.openAllDevices();
print("设备数量:$deviceCount");
},
child: const Text("连接设备")
),
ElevatedButton(
onPressed: () async {
var closeResult = await Terra.closeAllDevices();
print("关闭设备结果:$closeResult");
},
child: const Text("关闭所有设备")
),
ElevatedButton(
onPressed: () async {
var sn = await Terra.getDeviceSn();
print("设备SN$sn");
},
child: const Text("获取设备SN")
),
ElevatedButton(
onPressed: () async {
var res = await Terra.setIntegrationTime(10.00);
print("设置积分时间结果:$res");
},
child: const Text("设置积分时间")
),
ElevatedButton(
onPressed: () async {
var res = await Terra.setAverageTimes(3);
print("设置平均次数结果:$res");
},
child: const Text("设置平均次数")
),
ElevatedButton(
onPressed: () async {
var res = await Terra.setTriggerMode(0);
print("设置触发模式:$res");
},
child: const Text("设置触发模式")
),
ElevatedButton(
onPressed: () async {
var res = await Terra.isConnect();
print("是否连接:$res");
},
child: const Text("是否连接")
),
ElevatedButton(
onPressed: () async {
var spectrum = await Terra.getRamanSpectrum();
print("光谱:$spectrum");
},
child: const Text("获取光谱(处理后的光谱)")
),
ElevatedButton(
onPressed: () async {
var registerRes = await Terra.ramanMatchRegister();
print("注册结果:$registerRes");
},
child: const Text("算法注册")
),
],
),
),
),
);
}
}