This commit is contained in:
Developer
2026-05-18 17:58:11 +08:00
commit 194033514f
49 changed files with 3414 additions and 0 deletions

130
example/lib/main.dart Normal file
View File

@@ -0,0 +1,130 @@
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("算法注册")
),
],
),
),
),
);
}
}