更新分享

This commit is contained in:
wyf
2025-04-28 15:37:58 +08:00
parent 850c34b408
commit eae7a2284d
116 changed files with 12143 additions and 3017 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
class CustomCard extends StatefulWidget {
final double borderRadius; // 圆角
@@ -15,7 +16,7 @@ class CustomCard extends StatefulWidget {
required this.colors,
required this.child,
this.enableAnimation = true, // 默认启用动画效果
this.enableGradient = true, // 默认启用渐变效果
this.enableGradient = true, // 默认启用渐变效果
}) : super(key: key);
@override
@@ -25,36 +26,19 @@ class CustomCard extends StatefulWidget {
class _CustomCardState extends State<CustomCard>
with SingleTickerProviderStateMixin {
double _scale = 1.0;
final Duration _animationDuration = Duration(milliseconds: 50);
final GlobalKey _inkKey = GlobalKey();
final Duration _animationDuration = const Duration(milliseconds: 50);
Future<void> _handleTap(TapDownDetails details) async {
setState(() {
_scale = 0.95;
});
Future<void> _handleTap() async {
if (widget.enableAnimation) {
setState(() {
_scale = 0.95;
});
await Future.delayed(_animationDuration);
await Future.delayed(_animationDuration);
setState(() {
_scale = 1.0;
});
await Future.delayed(_animationDuration);
// 手动触发水波纹
final RenderBox? box =
_inkKey.currentContext?.findRenderObject() as RenderBox?;
if (box != null) {
final Offset localPosition = box.globalToLocal(details.globalPosition);
InkRipple.splashFactory.create(
controller: Material.of(_inkKey.currentContext!)!,
referenceBox: box,
position: localPosition,
color: widget.colors.first.withOpacity(0.2),
containedInkWell: true,
borderRadius: BorderRadius.circular(widget.borderRadius),
textDirection: Directionality.of(context),
);
setState(() {
_scale = 1.0;
});
}
widget.onTap();
@@ -62,51 +46,44 @@ class _CustomCardState extends State<CustomCard>
@override
Widget build(BuildContext context) {
final bool isGradient = widget.enableGradient && widget.colors.length > 1; // 只有启用渐变时,才使用渐变
final bool isGradient = widget.enableGradient && widget.colors.length > 1;
final Color baseColor = widget.colors.first;
return Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(widget.borderRadius),
child: GestureDetector(
onTapDown: _handleTap,
behavior: HitTestBehavior.translucent, // 关键:让空白区域也能点击
child: widget.enableAnimation // 判断是否启用动画
child: InkWell(
onTap: _handleTap,
borderRadius: BorderRadius.circular(widget.borderRadius),
splashColor: widget.colors.first.withOpacity(0.2),
child: widget.enableAnimation
? AnimatedScale(
scale: _scale,
duration: _animationDuration,
curve: Curves.easeInOut,
child: Ink(
key: _inkKey,
decoration: BoxDecoration(
color: isGradient ? null : baseColor,
gradient: isGradient
? LinearGradient(
colors: widget.colors,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
borderRadius: BorderRadius.circular(widget.borderRadius),
),
child: widget.child,
),
child: _buildContent(isGradient, baseColor),
)
: Ink(
key: _inkKey,
decoration: BoxDecoration(
color: isGradient ? null : baseColor,
gradient: isGradient
? LinearGradient(
colors: widget.colors,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
borderRadius: BorderRadius.circular(widget.borderRadius),
),
child: widget.child,
),
: _buildContent(isGradient, baseColor),
),
);
}
Widget _buildContent(bool isGradient, Color baseColor) {
return Container(
decoration: BoxDecoration(
color: isGradient ? null : baseColor,
gradient: isGradient
? LinearGradient(
colors: widget.colors,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
borderRadius: BorderRadius.circular(widget.borderRadius),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0.rpx, 0.rpx, 0.rpx, 5.rpx),
child: widget.child,
),
);
}

View File

@@ -0,0 +1,79 @@
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'CustomCard.dart';
class SelectableTagButton extends StatelessWidget {
final String label;
final bool selected;
final VoidCallback onTap;
final double minWidth; // 最小宽度单位dp会转 rpx
final double maxWidth; // 最大宽度单位dp会转 rpx
ThemeController themeController = Get.find();
SelectableTagButton({
Key? key,
required this.label,
required this.selected,
required this.onTap,
this.minWidth = 132, // 默认最小宽度
this.maxWidth = 500, // 默认最大宽度
}) : super(key: key);
@override
Widget build(BuildContext context) {
final double minWidthRpx = minWidth.rpx;
final double maxWidthRpx = maxWidth.rpx;
final double horizontalPadding = 28.rpx * 2; // 左右各 28总 56
// 估算文本宽度:每个字符按 14.rpx 字号估一个宽度
final double estimatedTextWidth = label.length * 33.rpx;
// 总宽度 = 文本宽度 + padding
final double totalWidth = estimatedTextWidth + horizontalPadding;
// 限制在 min 和 max 之间
final double constrainedWidth = totalWidth.clamp(minWidthRpx, maxWidthRpx);
return CustomCard(
onTap: onTap,
borderRadius: AppConstants().normal_container_radius,
colors: selected
? [themeController.currentColor.sc1, themeController.currentColor.sc2]
: [Colors.transparent],
// colors: [Colors.transparent],
enableGradient: true,
child: Container(
decoration: BoxDecoration(
border: selected
? null
: Border.all(
color: themeController.currentColor.sc4,
width: 1.rpx,
), // 未选中时无边框
borderRadius: BorderRadius.circular(12.0), // 如果需要圆角
),
padding: EdgeInsets.symmetric(horizontal: 28.rpx),
constraints: BoxConstraints(
minHeight: 61.rpx,
maxWidth: constrainedWidth,
),
alignment: Alignment.center,
child: Text(
label,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
color: selected
? themeController.currentColor.sc3
: themeController.currentColor.sc4,
fontSize: AppConstants().normal_text_fontSize, // 字体也用 rpx 控制
),
),
),
);
}
}

View File

@@ -0,0 +1,130 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
class TopSlideNotification extends StatefulWidget {
final String text;
double? fontSize = 26.rpx;
Color? textColor;
double? slideOffset = 200;
final Duration duration;
TopSlideNotification({
super.key,
this.text = '操作成功!',
this.fontSize,
this.textColor,
this.slideOffset,
this.duration = const Duration(seconds: 2),
});
@override
State<TopSlideNotification> createState() => _TopSlideNotificationState();
/// 工具方法:调用时直接加进 Overlay 上
static void show(
BuildContext context, {
String text = '操作成功!',
double fontSize = 16,
Color? textColor,
double slideOffset = 300.0,
Duration duration = const Duration(seconds: 2),
}) {
final overlay = Overlay.of(context);
final entry = OverlayEntry(
builder: (_) => TopSlideNotification(
text: text,
fontSize: fontSize,
textColor: textColor,
slideOffset: slideOffset,
duration: duration,
),
);
overlay.insert(entry);
Future.delayed(duration + const Duration(milliseconds: 500), () {
entry.remove();
});
}
}
class _TopSlideNotificationState extends State<TopSlideNotification>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<Offset> _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
SchedulerBinding.instance.addPostFrameCallback((_) async {
await _controller.forward();
await Future.delayed(widget.duration);
await _controller.reverse();
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final screenHeight = MediaQuery.of(context).size.height;
final offsetValue = widget.slideOffset! / screenHeight;
_animation = Tween<Offset>(
begin: const Offset(0, -1),
end: Offset(0, offsetValue),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeOut,
reverseCurve: Curves.easeIn,
));
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
Color get _textColor {
return widget.textColor ?? Get.find<ThemeController>().currentColor.sc2;
}
@override
Widget build(BuildContext context) {
return Positioned(
top: 0,
left: 0,
right: 0,
child: SlideTransition(
position: _animation,
child: Material(
color: stringToColor("#000000").withOpacity(0.8),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Container(
// color: Colors.red,
child: Text(
widget.text,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: widget.fontSize,
color: _textColor,
),
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,51 @@
// import 'package:flutter/material.dart';
// import 'package:webview_flutter/webview_flutter.dart';
// class WebViewWidget extends StatefulWidget {
// final String url;
// const WebViewWidget({Key? key, required this.url}) : super(key: key);
// @override
// _WebViewWidgetState createState() => _WebViewWidgetState();
// }
// class _WebViewWidgetState extends State<WebViewWidget> {
// late WebViewController _webViewController;
// @override
// void initState() {
// super.initState();
// // 初始化 WebView 控件
// WebView.platform = SurfaceAndroidWebView();
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text('WebView'),
// ),
// body: WebView(
// initialUrl: widget.url, // 设置要打开的网页地址
// javascriptMode: JavascriptMode.unrestricted, // 启用 JavaScript
// onWebViewCreated: (WebViewController webViewController) {
// _webViewController = webViewController;
// },
// onPageStarted: (String url) {
// print("页面开始加载:$url");
// },
// onPageFinished: (String url) {
// print("页面加载完成:$url");
// },
// navigationDelegate: (NavigationRequest request) {
// if (request.url.startsWith('https://www.google.com/')) {
// print('拦截了URL请求: ${request.url}');
// return NavigationDecision.prevent; // 拦截特定的请求
// }
// return NavigationDecision.navigate;
// },
// gestureNavigationEnabled: true, // 启用手势返回
// ),
// );
// }
// }

166
lib/component/tool/cmd.dart Normal file
View File

@@ -0,0 +1,166 @@
//蓝牙指令
// wifi列表指令
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
import 'package:easydevice/src/app/thapp.dart';
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
getWifiList(THapp tHapp) async {
try {
edm.EasyDartModule.logger.info("发送请求网络列表指令");
DailyLogUtils.writeLog("发送请求网络列表指令");
List data = [];
var wifilist = await tHapp.send("wscan scan", true, (log) {
print("[bles]${log.log}");
if (log.log.contains("SCAN RESULT OVER!")) {
final wifiList = <Map<String, dynamic>>[];
final items = log.log.split('[wifi]: SCAN RESULT ITEM:');
final reg =
RegExp(r'SSID=([^\t\r\n]+)\s+RSSI=(-?\d+)\s*,\s*auth\s*=\s*(\d+)');
for (var item in items) {
final match = reg.firstMatch(item);
if (match != null) {
wifiList.add({
'ssid': match.group(1),
'rssi': int.parse(match.group(2)!),
'auth': int.parse(match.group(3)!),
});
}
}
print('解析得到 Wi-Fi 列表: $wifiList');
if (wifiList.length != 0) {
log.result = wifiList;
data = wifiList;
log.over = true;
return true;
}
}
return false;
}, 10);
return wifilist;
} catch (e) {
print(e);
}
return [];
}
getWifiStatus(THapp tHapp) async {
edm.EasyDartModule.logger.info("发送请求设备网络状态指令");
DailyLogUtils.writeLog("发送请求设备网络状态指令");
var result = await tHapp.send(
"wl show",
true,
(ss) {
var log = ss.log;
final match = RegExp(r'status=([^\s]+)').firstMatch(log);
final status = match?.group(1);
if (status != null) {
print('提取到的 status: $status');
if (status == 'connect') {
ss.result = true;
ss.over = true;
return true;
} else {
ss.result = false;
ss.over = true;
return false;
}
} else {
return false;
}
},
);
return result;
}
Future<bool> sendWifiSetting(wifiItem, String password, THapp tHapp) async {
try {
edm.EasyDartModule.logger.info("发送wifi配置指令");
DailyLogUtils.writeLog("发送wifi配置指令->");
String cmd = "vtouch save update -a -i .wifi.sta.auth=${wifiItem['auth']} "
".wifi.sta.ssid=${wifiItem['ssid']} .wifi.sta.pwd=$password";
final success = await tHapp.send(cmd, true, (log) {
if (log.log.contains("update parm is successful")) {
print("[wifi456]:" + log.log);
edm.EasyDartModule.logger.info("WiFi配置成功-》log:$log");
DailyLogUtils.writeLog("WiFi配置成功->log:$log");
log.result = true;
log.over = true;
return true;
}
return false;
}, 10);
if (!success) {
edm.EasyDartModule.logger.error("WiFi配置超时或失败");
DailyLogUtils.writeLog("WiFi配置超时或失败");
}
return success;
} catch (e) {
edm.EasyDartModule.logger.error("发送wifi配置指令异常: ${e.toString()}");
DailyLogUtils.writeLog("发送wifi配置指令异常-> ${e.toString()}");
return false;
}
}
getDeviceWifiStatus(THapp tHapp) async {
edm.EasyDartModule.logger.info("发送请求设备已配置网络状态指令");
DailyLogUtils.writeLog("发送请求设备已配置网络状态指令");
var result = await tHapp.send(
"at+system info",
true,
(ss) {
var log = ss.log;
// 匹配设备状态
final statusMatch = RegExp(r'status=([^\s]+)').firstMatch(log);
final status = statusMatch?.group(1);
if (status != null) {
print('提取到的 status: $status');
// 如果设备连接状态是 "connect",继续检测
if (status == 'connect') {
ss.result = true;
ss.over = true;
// 匹配 Wi-Fi 连接信息
final wifiInfoMatch = RegExp(
r'WIFI CONNECTED INFO:SSID=([^\s]+),RSSI=([-0-9]+),AUTH=([0-9]+),CH=([0-9]+),BSSID=([A-F0-9]+)')
.firstMatch(log);
if (wifiInfoMatch != null) {
final ssid = wifiInfoMatch.group(1);
final rssi = wifiInfoMatch.group(2);
final auth = wifiInfoMatch.group(3);
final ch = wifiInfoMatch.group(4);
final bssid = wifiInfoMatch.group(5);
// 打印并返回 Wi-Fi 信息
print(
'Wi-Fi 信息: SSID=$ssid, RSSI=$rssi, AUTH=$auth, CH=$ch, BSSID=$bssid');
// 停止监听并返回信息
ss.result = {
'ssid': ssid,
'rssi': rssi,
'auth': auth,
'ch': ch,
'bssid': bssid,
};
ss.over = true;
return ss.result;
}
}
}
// 未找到状态或Wi-Fi信息时返回 false
return false;
},
);
return result;
}