更新太和e护配置wifi失败问题
This commit is contained in:
188
lib/component/tool/NewTopSlideNotification.dart
Normal file
188
lib/component/tool/NewTopSlideNotification.dart
Normal file
@@ -0,0 +1,188 @@
|
||||
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 NewTopSlideNotification extends StatefulWidget {
|
||||
final String text;
|
||||
final double fontSize;
|
||||
final Color? textColor;
|
||||
final double slideOffset;
|
||||
final Duration duration;
|
||||
|
||||
const NewTopSlideNotification({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.fontSize,
|
||||
this.textColor,
|
||||
required this.slideOffset,
|
||||
required this.duration,
|
||||
});
|
||||
|
||||
static OverlayEntry? _currentEntry;
|
||||
static bool _isShowing = false;
|
||||
|
||||
/// ✅ 不需要传 context
|
||||
static void show({
|
||||
String text = '操作成功!',
|
||||
double fontSize = 16,
|
||||
Color? textColor,
|
||||
double slideOffset = 300.0,
|
||||
Duration duration = const Duration(seconds: 2),
|
||||
}) {
|
||||
_showInternal(
|
||||
text: text,
|
||||
fontSize: fontSize,
|
||||
textColor: textColor,
|
||||
slideOffset: slideOffset,
|
||||
duration: duration,
|
||||
);
|
||||
}
|
||||
|
||||
static void _showInternal({
|
||||
required String text,
|
||||
required double fontSize,
|
||||
Color? textColor,
|
||||
required double slideOffset,
|
||||
required Duration duration,
|
||||
}) {
|
||||
// 移除现有弹窗
|
||||
_removeCurrentEntry();
|
||||
|
||||
// ✅ 自动获取全局可用的 context
|
||||
final context = Get.overlayContext ?? Get.context;
|
||||
if (context == null) {
|
||||
debugPrint('NewTopSlideNotification: 无法获取有效的上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
final overlay = Overlay.of(context);
|
||||
if (overlay == null) {
|
||||
debugPrint('NewTopSlideNotification: 未找到 Overlay');
|
||||
return;
|
||||
}
|
||||
|
||||
final entry = OverlayEntry(
|
||||
builder: (_) => NewTopSlideNotification(
|
||||
text: text,
|
||||
fontSize: fontSize,
|
||||
textColor: textColor,
|
||||
slideOffset: slideOffset,
|
||||
duration: duration,
|
||||
),
|
||||
);
|
||||
|
||||
_currentEntry = entry;
|
||||
_isShowing = true;
|
||||
overlay.insert(entry);
|
||||
|
||||
// 自动移除
|
||||
Future.delayed(duration + const Duration(milliseconds: 500), () {
|
||||
_removeCurrentEntry();
|
||||
});
|
||||
}
|
||||
|
||||
static void _removeCurrentEntry() {
|
||||
if (_currentEntry != null && _isShowing) {
|
||||
_currentEntry!.remove();
|
||||
_currentEntry = null;
|
||||
_isShowing = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
State<NewTopSlideNotification> createState() => _TopSlideNotificationState();
|
||||
}
|
||||
|
||||
class _TopSlideNotificationState extends State<NewTopSlideNotification>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<Offset> _animation;
|
||||
bool _isAnimating = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
_startAnimation();
|
||||
});
|
||||
}
|
||||
|
||||
@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 =>
|
||||
widget.textColor ?? Get.find<ThemeController>().currentColor.sc2;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Positioned(
|
||||
top: 140.rpx,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: SlideTransition(
|
||||
position: _animation,
|
||||
child: Material(
|
||||
color: stringToColor("#000000").withOpacity(0.8),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 20.rpx),
|
||||
child: Center(
|
||||
child: Text(
|
||||
widget.text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: widget.fontSize,
|
||||
color: _textColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _startAnimation() async {
|
||||
if (_isAnimating) return;
|
||||
_isAnimating = true;
|
||||
|
||||
try {
|
||||
await _controller.forward();
|
||||
await Future.delayed(widget.duration);
|
||||
if (mounted) {
|
||||
await _controller.reverse();
|
||||
}
|
||||
} finally {
|
||||
_isAnimating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,48 +3,57 @@ 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)
|
||||
final double minWidth; // 最小宽度
|
||||
final double maxWidth; // 最大宽度
|
||||
final double borderRadius; // ✅ 圆角(默认 12)
|
||||
final List<Color>? colors; // ✅ 可选渐变颜色
|
||||
final Color? selectedTextColor; // ✅ 选中文字颜色
|
||||
final Color? unselectedTextColor; // ✅ 未选中文字颜色
|
||||
|
||||
ThemeController themeController = Get.find();
|
||||
final ThemeController themeController = Get.find();
|
||||
|
||||
SelectableTagButton({
|
||||
Key? key,
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
this.minWidth = 132, // 默认最小宽度
|
||||
this.maxWidth = 500, // 默认最大宽度
|
||||
this.minWidth = 132,
|
||||
this.maxWidth = 500,
|
||||
this.borderRadius = 12.0,
|
||||
this.colors,
|
||||
this.selectedTextColor,
|
||||
this.unselectedTextColor,
|
||||
}) : 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 horizontalPadding = 28.rpx * 2;
|
||||
final double estimatedTextWidth = label.length * 33.rpx;
|
||||
|
||||
// 总宽度 = 文本宽度 + padding
|
||||
final double totalWidth = estimatedTextWidth + horizontalPadding;
|
||||
|
||||
// 限制在 min 和 max 之间
|
||||
final double constrainedWidth = totalWidth.clamp(minWidthRpx, maxWidthRpx);
|
||||
|
||||
// ✅ 背景渐变颜色
|
||||
final List<Color> effectiveColors = colors ??
|
||||
[themeController.currentColor.sc1, themeController.currentColor.sc2];
|
||||
|
||||
// ✅ 字体颜色逻辑
|
||||
final Color effectiveTextColor = selected
|
||||
? (selectedTextColor ?? themeController.currentColor.sc3)
|
||||
: (unselectedTextColor ?? themeController.currentColor.sc4);
|
||||
|
||||
return CustomCard(
|
||||
onTap: onTap,
|
||||
borderRadius: AppConstants().normal_container_radius,
|
||||
colors: selected
|
||||
? [themeController.currentColor.sc1, themeController.currentColor.sc2]
|
||||
: [Colors.transparent],
|
||||
// colors: [Colors.transparent],
|
||||
borderRadius: borderRadius,
|
||||
colors: selected ? effectiveColors : [Colors.transparent],
|
||||
enableGradient: true,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -53,8 +62,8 @@ class SelectableTagButton extends StatelessWidget {
|
||||
: Border.all(
|
||||
color: themeController.currentColor.sc4,
|
||||
width: 0.5.rpx,
|
||||
), // 未选中时无边框
|
||||
borderRadius: BorderRadius.circular(12.0), // 如果需要圆角
|
||||
),
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 28.rpx),
|
||||
constraints: BoxConstraints(
|
||||
@@ -67,10 +76,8 @@ class SelectableTagButton extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: selected
|
||||
? themeController.currentColor.sc3
|
||||
: themeController.currentColor.sc4,
|
||||
fontSize: AppConstants().normal_text_fontSize, // 字体也用 rpx 控制
|
||||
color: effectiveTextColor,
|
||||
fontSize: AppConstants().normal_text_fontSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class TopSlideNotification extends StatefulWidget {
|
||||
BuildContext?context;
|
||||
BuildContext? context;
|
||||
final String text;
|
||||
double? fontSize = 26.rpx;
|
||||
Color? textColor;
|
||||
|
||||
Reference in New Issue
Block a user