新增一个chat_popup 来显示聊天窗口
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:ui';
|
||||
import '../widgets/chat_box.dart';
|
||||
import '../screens/full_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/message_service.dart';
|
||||
import '../widgets/gradient_background.dart';
|
||||
import '../utils/assets_util.dart';
|
||||
import '../pages/full_screen.dart';
|
||||
|
||||
class PartScreen extends StatefulWidget {
|
||||
final VoidCallback? onHide;
|
||||
@@ -66,7 +66,7 @@ class _PartScreenState extends State<PartScreen> {
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider.value(
|
||||
value: messageService, // 传递同一个单例实例
|
||||
child: const FullScreen(),
|
||||
child: const FullScreenPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -76,13 +76,21 @@ class _PartScreenState extends State<PartScreen> {
|
||||
EdgeInsets _calculatePosition(BoxConstraints constraints) {
|
||||
final screenWidth = constraints.maxWidth;
|
||||
final screenHeight = constraints.maxHeight;
|
||||
final iconX = screenWidth - widget.floatingIconPosition.dx;
|
||||
final iconY = screenHeight - widget.floatingIconPosition.dy;
|
||||
|
||||
// 聊天框的尺寸
|
||||
final chatWidth = screenWidth * 0.94;
|
||||
final maxChatHeight = screenHeight * 0.4;
|
||||
|
||||
final iconX = screenWidth - widget.floatingIconPosition.dx;
|
||||
final iconY = screenHeight - widget.floatingIconPosition.dy;
|
||||
|
||||
// 1. 先将icon的right/bottom转为屏幕坐标(icon左下角)
|
||||
var iconPosition = widget.floatingIconPosition;
|
||||
|
||||
final iconLeft = screenWidth - iconPosition.dx - widget.iconSize;
|
||||
final iconBottom = iconPosition.dy;
|
||||
final iconTop = iconBottom + widget.iconSize;
|
||||
final iconCenterX = iconLeft + widget.iconSize / 2;
|
||||
|
||||
// 判断FloatingIcon在屏幕的哪一边
|
||||
final isOnRightSide = iconX < screenWidth / 2;
|
||||
|
||||
@@ -96,18 +104,31 @@ class _PartScreenState extends State<PartScreen> {
|
||||
leftPadding = screenWidth - chatWidth - (screenWidth - chatWidth) * 0.1;
|
||||
}
|
||||
|
||||
// 计算垂直位置,确保聊天框在图标上方
|
||||
double bottomPadding = iconY + widget.iconSize + 20;
|
||||
// 优先尝试放在icon上方
|
||||
double chatBottom = iconTop + 12; // 聊天框底部距离icon顶部12px
|
||||
double chatTop = screenHeight - chatBottom - maxChatHeight;
|
||||
|
||||
// 确保聊天框不会超出屏幕
|
||||
final minBottomPadding = screenHeight * 0.15;
|
||||
final maxBottomPadding = screenHeight - maxChatHeight - 50;
|
||||
bottomPadding = bottomPadding.clamp(minBottomPadding, maxBottomPadding);
|
||||
// 如果上方空间不足,则放在icon下方
|
||||
if (chatTop < 0) {
|
||||
chatBottom = iconBottom - 12 - maxChatHeight / 2; // 聊天框顶部距离icon底部12px
|
||||
// 如果下方也不足,则贴底
|
||||
if (chatBottom < 0) {
|
||||
chatBottom = 20; // 距离底部20px
|
||||
}
|
||||
}
|
||||
|
||||
// // 计算垂直位置,确保聊天框在图标上方
|
||||
// double bottomPadding = iconY + widget.iconSize + 20;
|
||||
//
|
||||
// // 确保聊天框不会超出屏幕
|
||||
// final minBottomPadding = screenHeight * 0.15;
|
||||
// final maxBottomPadding = screenHeight - maxChatHeight - 50;
|
||||
// bottomPadding = bottomPadding.clamp(minBottomPadding, maxBottomPadding);
|
||||
|
||||
return EdgeInsets.only(
|
||||
left: leftPadding,
|
||||
right: screenWidth - leftPadding - chatWidth,
|
||||
bottom: bottomPadding,
|
||||
bottom: chatBottom,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user