circle_app/circle_app/lib/view/notice.dart

171 lines
6.1 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
typedef void NoticeCallback();
void showFloatingButtonOverlay(
BuildContext context, String nickname, String ageMsg, String avatar,NoticeCallback noticeCallback) {
OverlayState? overlayState = Overlay.of(context);
late OverlayEntry overlayEntry;
bool showMessage = false;
int countdownSeconds = 5; // 倒计时秒数
// 创建 Timer
late Timer countdownTimer;
// 创建 OverlayEntry
overlayEntry = OverlayEntry(
builder: (BuildContext context) {
return Positioned(
top: 30,
// right: 16,
child: AnimatedContainer(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
height: showMessage ? 95 : 0,
child: Container(
width: Get.width - 16,
margin: EdgeInsets.all(10.sp),
padding: EdgeInsets.fromLTRB(16.sp, 16.sp, 16.sp, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xFF353443),
),
child: SingleChildScrollView(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipOval(
child: CachedNetworkImage(
fit: BoxFit.cover,
placeholder: null,
imageUrl: avatar,
width: 48.sp,
height: 48.sp,
),
),
const SizedBox(width: 8),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 50.sp,
child: Text(
nickname,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 14,
),
),
),
SizedBox(width: 8.sp),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17),
gradient: const LinearGradient(
colors: [
Color.fromRGBO(141, 255, 248, 1.0),
Color.fromRGBO(181, 211, 255, 1.0),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
padding: EdgeInsets.only(
top: 2.sp,
bottom: 2.sp,
left: 10.sp,
right: 10.sp,
),
child: Text(
ageMsg,
style: const TextStyle(
color: Colors.black,
fontSize: 10,
),
),
),
],
),
const SizedBox(height: 8),
Text(
"看了这么久,给我点个喜欢呗~",
style: TextStyle(
color: Colors.grey,
fontSize: 12.sp,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
const Spacer(),
GestureDetector(
onTap: () {
countdownTimer.cancel(); // 取消计时器
overlayEntry.remove();
noticeCallback();
// logic.setLike();
// logic.showMessage = false;
// logic.update();
},
child: Container(
margin: EdgeInsets.only(top: 6.sp),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17),
gradient: const LinearGradient(
colors: [
Color(0xFF06F9FA),
Color(0xFFDC5BFD),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
padding: EdgeInsets.symmetric(
horizontal: 16.sp, vertical: 6.sp),
child: Text(
"喜欢",
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
),
),
),
// ),
],
),
),
),
),
);
},
);
// setState(() {});
showMessage = true;
countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (countdownSeconds > 0) {
countdownSeconds--;
// overlayEntry.markNeedsBuild(); // 刷新 OverlayEntry
} else {
timer.cancel(); // 取消计时器
overlayEntry.remove(); // 移除 OverlayEntry
}
});
// 将 OverlayEntry 添加到 Overlay 中
overlayState?.insert(overlayEntry);
}