circle_app/circle_app/lib/view/notice.dart
2024-08-13 09:42:07 +08:00

543 lines
20 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:circle_app/commons/colors/app_color.dart';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../main.dart';
import '../router/routers.dart';
import '../utils/cache_img.dart';
typedef void NoticeCallback();
void showFloatingButtonOverlay(BuildContext context, String nickname,
String ageMsg, String avatar, int event, 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 Stack(
alignment: Alignment.center,
children: [
Positioned(
top: MediaQuery.of(context).padding.top,
// right: 16,
child: AnimatedContainer(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
height: showMessage ? 85 : 0,
child: Container(
width: Get.width - 16,
// margin: EdgeInsets.only(top:10.sp),
padding: EdgeInsets.fromLTRB(16.sp, 16.sp, 16.sp, 16.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xFF353443),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipOval(
child: CachedImg(
fit: BoxFit.cover,
imageUrl: avatar,
width: 48.sp,
height: 48.sp,
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
// width: 70.sp,
child: Text(
nickname,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 16.sp,
),
),
),
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: 4),
Text(
event == 0
? "看了这么久,给我点个喜欢呗~"
: event == 1
? "我喜欢了你,可以喜欢我一下吗?"
: event == 2
? "你喜欢的人上线啦,赶紧找他聊天吧!"
: "我也喜欢了你,一起聊聊呗~",
style: TextStyle(
color: Colors.grey,
fontSize: 13.sp,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
GestureDetector(
onTap: () {
countdownTimer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
noticeCallback();
// logic.setLike();
// logic.showMessage = false;
// logic.update();
},
child: Container(
margin: EdgeInsets.only(top: 6.sp),
height: 34,
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(
event == 0
? "喜欢"
: event == 1
? "回关"
: event == 2
? "私聊"
: "私聊",
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
),
),
),
// ),
],
),
),
),
),
if (event == 0)
Positioned(
top: MediaQuery.of(context).padding.top,
right: 8,
child: GestureDetector(
onTap: () {
countdownTimer.cancel();
// 取消计时器
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
},
child: Container(
height: 20,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10)),
gradient: AppColor.mainVerLinearGradient),
alignment: Alignment.center,
child: Icon(
Icons.close,
size: 20,
color: Colors.white,
),
),
))
],
);
},
);
// setState(() {});
showMessage = true;
mainOverlayEntry = overlayEntry;
countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (countdownSeconds > 0) {
countdownSeconds--;
// overlayEntry.markNeedsBuild(); // 刷新 OverlayEntry
} else {
// 取消计时器
timer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
}
});
// 将 OverlayEntry 添加到 Overlay 中
overlayState?.insert(overlayEntry!);
}
void showGiftButtonOverlay(BuildContext context,String content,
Map sendUser, Map recevierUser, 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 Stack(
alignment: Alignment.center,
children: [
Positioned(
top: MediaQuery.of(context).padding.top,
// right: 16,
child: AnimatedContainer(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
height: showMessage ? 55 : 0,
child: Container(
width: Get.width - 8,
// margin: EdgeInsets.only(top:10.sp),
padding: EdgeInsets.fromLTRB(8.sp, 8.sp, 8.sp, 8.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xFF353443),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// const SizedBox(width: 8),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
// direction: Axis.vertical,
children: [
GestureDetector(
onTap: () {
countdownTimer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
Get.toNamed(Routes.UserInfoPage,arguments:sendUser['id'].toString());
},
child: Row(
children: [
ClipOval(
child: CachedImg(
fit: BoxFit.cover,
imageUrl: sendUser['avatar'],
width: 30.sp,
height: 30.sp,
),
),
Container(
// width: 70.sp,
child: Text(
sendUser['nickname'],
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: AppColor.mainColor,
fontSize: 15.sp,
),
),
),
],
),
),
Container(
// width: 70.sp,
child: Text(
'',
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 15.sp,
),
),
),
GestureDetector(
onTap: () {
countdownTimer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
Get.toNamed(Routes.UserInfoPage,arguments:recevierUser['id'].toString());
},
child: Container(
// width: 70.sp,
child: Text(
recevierUser['nickname'],
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: AppColor.mainColor,
fontSize: 15.sp,
),
),
),
),
Container(
// width: 70.sp,
child: Text(
'礼物' + content.split(recevierUser['nickname']).last,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color.fromRGBO(247, 250, 250, 1.0),
fontSize: 15.sp,
),
),
),
],
),
),
GestureDetector(
onTap: () {
countdownTimer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
noticeCallback();
// logic.setLike();
// logic.showMessage = false;
// logic.update();
},
child: Container(
// margin: EdgeInsets.only(top: 6.sp),
height: 24,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: const LinearGradient(
colors: [
Color(0xFF06F9FA),
Color(0xFFDC5BFD),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
padding: EdgeInsets.symmetric(
horizontal: 8.sp, vertical: 0.sp),
child: Text(
'围观',
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
),
),
),
// ),
],
),
),
),
),
Positioned(
top: MediaQuery.of(context).padding.top,
right: 5.sp,
child: GestureDetector(
onTap: () {
countdownTimer.cancel();
// 取消计时器
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
},
child: Container(
height: 15,
width: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10)),
gradient: AppColor.tagVerLinearGradient),
alignment: Alignment.center,
child: Icon(
Icons.close,
size: 15,
color: Colors.white,
),
),
))
],
);
},
);
// setState(() {});
showMessage = true;
mainOverlayEntry = overlayEntry;
countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (countdownSeconds > 0) {
countdownSeconds--;
// overlayEntry.markNeedsBuild(); // 刷新 OverlayEntry
} else {
// 取消计时器
timer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
}
});
// 将 OverlayEntry 添加到 Overlay 中
overlayState?.insert(overlayEntry!);
}
void showTipFloatingButtonOverlay(BuildContext context, String tip) {
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 Column(
children: [
GestureDetector(
onTap: () {
countdownTimer.cancel();
// 取消计时器
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
Get.toNamed(Routes.UserInfoPage);
},
child: Container(
width: Get.width - 16,
height: 40.sp,
margin: EdgeInsets.only(top:MediaQuery.of(context).padding.top + 45),
padding: EdgeInsets.fromLTRB(16.sp, 0.sp, 16.sp, 0.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Color(0xFF353443).withOpacity(0.5),
),
child: Row(
children: [
Expanded(
child: Text(
tip,
style: TextStyle(
color: Colors.grey,
fontSize: 13.sp,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
)),
GestureDetector(
onTap: () {
countdownTimer.cancel();
// 取消计时器
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
},
child: Icon(
Icons.close,
size: 20,
color: AppColor.mainColor,
),
)
],
),
),
),
],
);
},
);
// setState(() {});
showMessage = true;
mainOverlayEntry = overlayEntry;
countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (countdownSeconds > 0) {
countdownSeconds--;
// overlayEntry.markNeedsBuild(); // 刷新 OverlayEntry
} else {
// 取消计时器
timer.cancel();
try {
overlayEntry!.remove();
} catch (e) {}
mainOverlayEntry = null;
}
});
// 将 OverlayEntry 添加到 Overlay 中
overlayState?.insert(overlayEntry!);
}