123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- import 'dart:async';
- import 'dart:math';
- import 'package:fis_lib_basictest/hardware_detection/index.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- void main() {
- runApp(const MyApp());
- }
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return GetMaterialApp(
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- initialRoute: '/',
- getPages: [
- GetPage(
- name: '/',
- page: () => HardwareDetectionPage(),
- binding: HardwareDetectionBinding(),
- ),
- GetPage(name: '/old', page: () => DrawWidgetStep2()),
- ],
- );
- }
- }
- class DrawWidgetStep2 extends StatefulWidget {
- const DrawWidgetStep2({Key? key}) : super(key: key);
- @override
- State<StatefulWidget> createState() => DrawWidgetStep2State();
- }
- class DrawWidgetStep2State extends State<DrawWidgetStep2>
- with TickerProviderStateMixin {
- late Timer timer;
- AnimationController? controller;
- late Animation<double> strokePercentAnimation;
- late Animation<double> labelPercentAnimation;
- late Animation<Color?> strokeColorAnimation;
- late double beginPercentValue;
- late double endPercentValue;
- late Color beginColor;
- late Color endColor;
- late double speechSliderValue = 0;
- late double microPhoneSliderValue = 0;
- late String speechSliderText = "0";
- late String microphoneSliderText = "0";
- @override
- void initState() {
- super.initState();
- // 设置初始值结束值
- beginPercentValue = 0;
- endPercentValue = 0;
- beginColor = Colors.black;
- endColor = ([...Colors.primaries]..shuffle()).first;
- // 动画控制器初始化
- controller = AnimationController(
- vsync: this, duration: const Duration(milliseconds: 1000));
- // 添加监听
- controller?.addListener(() => setState(() {}));
- // 开始执行动画
- startAnimation();
- // 设置定时器
- timer = Timer.periodic(const Duration(milliseconds: 300), (timer) {
- startAnimation();
- });
- }
- void startAnimation() {
- // 进度条动画
- strokePercentAnimation =
- Tween<double>(begin: beginPercentValue, end: endPercentValue).animate(
- CurvedAnimation(parent: controller!, curve: Curves.elasticOut));
- // text动画
- labelPercentAnimation =
- Tween<double>(begin: beginPercentValue, end: endPercentValue).animate(
- CurvedAnimation(parent: controller!, curve: Curves.easeInOutCubic));
- // 进度条颜色动画
- strokeColorAnimation = ColorTween(begin: beginColor, end: endColor).animate(
- CurvedAnimation(parent: controller!, curve: Curves.easeInOutCubic));
- beginPercentValue = endPercentValue;
- endPercentValue = Random().nextDouble();
- beginColor = endColor;
- endColor = ([...Colors.primaries]..shuffle()).first;
- controller?.forward(from: 1);
- }
- @override
- void dispose() {
- controller?.dispose();
- timer.cancel();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: FPadding(
- padding: const EdgeInsets.symmetric(vertical: 10),
- child: FSingleChildScrollView(
- child: FColumn(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildNetworkTest(),
- _buildSpeechTest(),
- _buildMicroPhoneTest(),
- _buildCameraTest(),
- ],
- ),
- ),
- ));
- }
- _buildNetworkTest() {
- var title = _bildTestTitle("网络检测");
- var testButton = _buildTestButton("网络检测");
- var networkTestItems = _buildNetworkTestItems();
- var divider = _buildDevider();
- return FColumn(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- title,
- testButton,
- ...networkTestItems,
- divider,
- ],
- );
- }
- _buildSpeechTest() {
- var title = _bildTestTitle("扬声器检测");
- var divider = _buildDevider();
- var speechSelections = _buildSpeechSelections();
- var speechResult = _buildTestItem(
- title: "扬声器状态",
- value: -1,
- valueUnit: "",
- testResult: "满足要求",
- isTestPass: true,
- );
- var speechButton = _buildTestButton("扬声器检测");
- var volumeSlider = _buildVolumSlider("扬声器音量", true);
- var mediaWave = _buildMediaWaves(false);
- var testResultActionButtonGroup = FContainer(
- padding: EdgeInsets.fromLTRB(0, 10, 10, 10),
- width: 250,
- child: FRow(
- children: [
- FContainer(
- width: 100,
- child: _buildTestButton("听到了"),
- ),
- FContainer(
- width: 100,
- child: _buildTestButton("没听到"),
- )
- ],
- ),
- );
- return FColumn(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- title,
- speechSelections,
- volumeSlider,
- speechButton,
- mediaWave,
- testResultActionButtonGroup,
- speechResult,
- divider,
- ],
- );
- }
- FWidget _buildVolumSlider(String title, bool isSpeechSlider) {
- return FContainer(
- width: 500,
- padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
- child: FRow(
- children: [
- FContainer(
- width: 140,
- child: FText(
- title,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- FContainer(
- width: 310,
- child: _buidSlider(isSpeechSlider),
- ),
- FText(
- isSpeechSlider ? speechSliderText : microphoneSliderText,
- ),
- ],
- ),
- );
- }
- void updateSlider(value, text, isSpeech) {
- if (isSpeech) {
- speechSliderValue = value;
- speechSliderText = text;
- } else {
- microPhoneSliderValue = value;
- microphoneSliderText = text;
- }
- setState(() {});
- }
- _buildMicroPhoneTest() {
- var title = _bildTestTitle("麦克风检测");
- var divider = _buildDevider();
- var mediaWave = _buildMediaWaves(true);
- var microPhoneResult = _buildTestItem(
- title: "麦克风状态",
- value: -1,
- valueUnit: "",
- testResult: "满足要求",
- isTestPass: true,
- );
- var microphpneButton = _buildTestButton("麦克风测试");
- var volumeSlider = _buildVolumSlider("麦克风音量", false);
- var microphoneSelection = _buildMicrophoneSelections();
- return FColumn(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- title,
- microphoneSelection,
- volumeSlider,
- microphpneButton,
- mediaWave,
- microPhoneResult,
- divider,
- ],
- );
- }
- _buildMediaWaves(bool isMicrophone) {
- var mediaWave = FContainer(
- padding: EdgeInsets.fromLTRB(13, 10, 10, 10),
- child: FSizedBox(
- width: 100,
- height: 10,
- child: FCustomPaint(
- painter: DrawPainter(
- strokeBackgroundColor: Colors.grey.withOpacity(0.1),
- strokeColor: Colors.red,
- startAngle: -pi * 0.5,
- percent: 0,
- percentLabel: "0",
- strokeWidth: 1,
- fontSize: 2,
- ),
- ),
- ),
- );
- return mediaWave;
- }
- _buildCameraTest() {
- var title = _bildTestTitle("摄像头检测");
- var cameraSelection = _buildCameraSelections();
- var devider = _buildDevider();
- var cameraResult = _buildTestItem(
- title: "摄像头状态",
- value: -1,
- valueUnit: "",
- testResult: "满足要求",
- isTestPass: true,
- );
- var testResultActionButtonGroup = FContainer(
- padding: EdgeInsets.fromLTRB(0, 10, 10, 10),
- width: 250,
- child: FRow(
- children: [
- FContainer(
- width: 100,
- child: _buildTestButton("看到了"),
- ),
- FContainer(
- width: 100,
- child: _buildTestButton("没看到"),
- )
- ],
- ),
- );
- var image = FContainer(
- margin: EdgeInsets.fromLTRB(8, 10, 10, 10),
- width: 640,
- height: 480,
- color: Colors.black,
- );
- var cameraStatement = FContainer(
- padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
- child: FText("该摄像头用于会诊时采集本地画面,请确认是否成功看到画面。"),
- );
- return FColumn(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- title,
- cameraSelection,
- image,
- cameraStatement,
- testResultActionButtonGroup,
- cameraResult,
- devider,
- ],
- );
- }
- FWidget _buidSlider(bool isSpeechSlider) {
- return FSlider(
- value: isSpeechSlider ? speechSliderValue : microPhoneSliderValue,
- max: 100,
- onChanged: (value) {
- var intValue = value.toInt();
- updateSlider(value, "$intValue", isSpeechSlider);
- },
- onChangeStart: (value) {
- var intValue = value.toInt();
- updateSlider(value, "$intValue", isSpeechSlider);
- },
- onChangeEnd: (value) {
- var intValue = value.toInt();
- updateSlider(value, " $intValue", isSpeechSlider);
- },
- );
- }
- _bildTestTitle(String title) {
- return FContainer(
- padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
- child: FText(
- title,
- style: TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- );
- }
- FWidget _buildTestButton(String content) {
- return FContainer(
- padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
- child: FInkWell(
- child: FText(content),
- onTap: () => {},
- ),
- );
- }
- List<FWidget> _buildNetworkTestItems() {
- var testItems = <FWidget>[];
- testItems.add(_buildTestItem(
- title: "网络延迟",
- value: 1,
- valueUnit: "ms",
- testResult: "满足要求",
- isTestPass: true,
- ));
- testItems.add(_buildTestItem(
- title: "上传速度",
- value: 342,
- valueUnit: "Mbps",
- testResult: "满足要求",
- isTestPass: true,
- ));
- testItems.add(_buildTestItem(
- title: "下载速度",
- value: 350,
- valueUnit: "Mbps",
- testResult: "满足要求",
- isTestPass: true,
- ));
- testItems.add(_buildTestItem(
- title: "视频服务质量",
- value: 20,
- valueUnit: "ms",
- testResult: "不满足要求",
- isTestPass: false,
- ));
- testItems.add(_buildTestItem(
- title: "网络质量",
- value: -1,
- valueUnit: "",
- testResult: "一般",
- isTestPass: false,
- ));
- return testItems;
- }
- FWidget _buildTestItem({
- required String title,
- required int value,
- required String valueUnit,
- required String testResult,
- required bool isTestPass,
- }) {
- var color = isTestPass ? Colors.green : Colors.red;
- return FContainer(
- padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
- width: 500,
- child: FRow(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- FContainer(
- width: 125,
- margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
- child: FText(
- title,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- FContainer(
- width: 125,
- child: FText(value == -1 ? "" : value.toString() + valueUnit),
- ),
- FContainer(
- width: 125,
- child: FText(
- testResult,
- style: TextStyle(
- color: color,
- ),
- ),
- ),
- FContainer(
- width: 60,
- child: isTestPass
- ? FIcon(
- Icons.check_circle_outline,
- color: color,
- )
- : FIcon(
- Icons.highlight_off_rounded,
- color: color,
- ),
- ),
- ],
- ),
- );
- }
- FWidget _buildDevider() {
- return FDivider(
- height: 15,
- thickness: 1,
- color: Colors.black,
- indent: 10,
- );
- }
- FWidget _buildSpeechSelections() {
- var devices = <DeviceModel>[];
- devices.add(DeviceModel(name: "扬声器1", id: "1"));
- devices.add(DeviceModel(name: "扬声器2", id: "2"));
- devices.add(DeviceModel(name: "扬声器3", id: "3"));
- return _buildDeviceSelections(devices);
- }
- FWidget _buildMicrophoneSelections() {
- var devices = <DeviceModel>[];
- devices.add(DeviceModel(name: "麦克风1", id: "1"));
- devices.add(DeviceModel(name: "麦克风2", id: "2"));
- devices.add(DeviceModel(name: "麦克风3", id: "3"));
- return _buildDeviceSelections(devices);
- }
- FWidget _buildCameraSelections() {
- var devices = <DeviceModel>[];
- devices.add(DeviceModel(name: "摄像头1", id: "1"));
- devices.add(DeviceModel(name: "摄像头2", id: "2"));
- devices.add(DeviceModel(name: "摄像头3", id: "3"));
- return _buildDeviceSelections(devices);
- }
- FWidget _buildDeviceSelections(List<DeviceModel> source) {
- return FContainer(
- margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
- child: FSelect<DeviceModel, String>(
- source: source,
- height: 33,
- width: 250,
- value: "1",
- optionValueExtractor: (value) {
- return value.id;
- },
- optionLabelExtractor: (value) {
- return value.name;
- },
- onSelectChanged: (value, index) {
- ;
- },
- fontSize: 14,
- ),
- );
- }
- }
- class DeviceModel {
- DeviceModel({
- required this.name,
- required this.id,
- });
- final String name;
- final String id;
- }
- class DrawPainter extends CustomPainter {
- final double strokeWidth;
- final Color strokeColor;
- final Color strokeBackgroundColor;
- final double startAngle;
- final double percent;
- final double fontSize;
- final Color textColor;
- final String? percentLabel;
- DrawPainter({
- this.strokeWidth = 10,
- this.strokeColor = Colors.black,
- this.strokeBackgroundColor = Colors.grey,
- this.startAngle = 0,
- this.percent = 0,
- this.fontSize = 20,
- this.textColor = Colors.black,
- this.percentLabel,
- });
- @override
- void paint(Canvas canvas, Size size) {
- //backgroud
- for (var i = 0; i < 15; i++) {
- var scolor = Colors.grey;
- var paint = Paint()
- ..style = PaintingStyle.stroke
- ..color = scolor
- ..strokeWidth = 3;
- var left = i * 10.0;
- var rect = Rect.fromLTWH(left, 2, 3, 20);
- canvas.drawRect(rect, paint);
- }
- var random = Random().nextInt(15);
- for (var i = 0; i < random; i++) {
- var scolor = Colors.blue;
- var paint = Paint()
- ..style = PaintingStyle.stroke
- ..color = scolor
- ..strokeWidth = 4;
- var left = i * 10.0;
- var rect = Rect.fromLTWH(left, 2, 3, 20);
- canvas.drawRect(rect, paint);
- }
- }
- @override
- bool shouldRepaint(CustomPainter oldDelegate) {
- return oldDelegate != this;
- }
- }
|