2023-01-30 21:40:13 +08:00
|
|
|
import 'package:auto_size_text/auto_size_text.dart';
|
2024-06-23 11:06:47 +08:00
|
|
|
import 'package:debounce_throttle/debounce_throttle.dart';
|
2022-05-02 16:02:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hbb/common.dart';
|
2024-06-23 11:06:47 +08:00
|
|
|
import 'package:flutter_hbb/models/platform_model.dart';
|
2023-02-06 23:11:48 +08:00
|
|
|
import 'package:get/get.dart';
|
2022-09-27 23:05:11 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2022-05-02 16:02:49 +08:00
|
|
|
|
2022-10-26 20:13:32 +08:00
|
|
|
import '../../consts.dart';
|
2022-09-13 09:29:19 +08:00
|
|
|
import '../../desktop/widgets/tabbar_widget.dart';
|
2022-08-11 10:19:12 +08:00
|
|
|
import '../../models/chat_model.dart';
|
2022-09-27 23:05:11 +08:00
|
|
|
import '../../models/model.dart';
|
2022-10-25 20:36:01 +08:00
|
|
|
import 'chat_page.dart';
|
2022-05-02 16:02:49 +08:00
|
|
|
|
|
|
|
class DraggableChatWindow extends StatelessWidget {
|
2022-09-13 09:29:19 +08:00
|
|
|
const DraggableChatWindow(
|
|
|
|
{Key? key,
|
|
|
|
this.position = Offset.zero,
|
2022-08-11 10:19:12 +08:00
|
|
|
required this.width,
|
|
|
|
required this.height,
|
2023-09-04 23:17:45 +08:00
|
|
|
required this.chatModel})
|
2022-09-13 09:29:19 +08:00
|
|
|
: super(key: key);
|
2022-05-02 16:02:49 +08:00
|
|
|
|
|
|
|
final Offset position;
|
|
|
|
final double width;
|
|
|
|
final double height;
|
2022-08-11 10:19:12 +08:00
|
|
|
final ChatModel chatModel;
|
2022-05-02 16:02:49 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-23 11:06:47 +08:00
|
|
|
if (draggablePositions.chatWindow.isInvalid()) {
|
|
|
|
draggablePositions.chatWindow.update(position);
|
|
|
|
}
|
2023-09-01 14:38:33 +08:00
|
|
|
return isIOS
|
2023-10-27 15:44:07 +08:00
|
|
|
? IOSDraggable(
|
2024-06-23 11:06:47 +08:00
|
|
|
position: draggablePositions.chatWindow,
|
2023-10-27 15:44:07 +08:00
|
|
|
chatModel: chatModel,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
builder: (context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
_buildMobileAppBar(context),
|
|
|
|
Expanded(
|
|
|
|
child: ChatPage(chatModel: chatModel),
|
2022-05-02 16:02:49 +08:00
|
|
|
),
|
2023-10-27 15:44:07 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: Draggable(
|
|
|
|
checkKeyboard: true,
|
2024-06-23 11:06:47 +08:00
|
|
|
position: draggablePositions.chatWindow,
|
2023-10-27 15:44:07 +08:00
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
chatModel: chatModel,
|
|
|
|
builder: (context, onPanUpdate) {
|
|
|
|
final child = Scaffold(
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
appBar: CustomAppBar(
|
|
|
|
onPanUpdate: onPanUpdate,
|
2024-03-28 11:38:11 +08:00
|
|
|
appBar: (isDesktop || isWebDesktop)
|
2023-10-27 15:44:07 +08:00
|
|
|
? _buildDesktopAppBar(context)
|
|
|
|
: _buildMobileAppBar(context),
|
|
|
|
),
|
|
|
|
body: ChatPage(chatModel: chatModel),
|
|
|
|
);
|
|
|
|
return Container(
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(border: Border.all(color: MyTheme.border)),
|
|
|
|
child: child);
|
|
|
|
});
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
2022-09-13 09:29:19 +08:00
|
|
|
|
2022-09-23 16:31:50 +08:00
|
|
|
Widget _buildMobileAppBar(BuildContext context) {
|
2022-09-13 09:29:19 +08:00
|
|
|
return Container(
|
2022-09-23 16:31:50 +08:00
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2022-09-13 09:29:19 +08:00
|
|
|
height: 50,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: Text(
|
|
|
|
translate("Chat"),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontFamily: 'WorkSans',
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 20),
|
|
|
|
)),
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
chatModel.hideChatWindowOverlay();
|
|
|
|
},
|
2023-05-29 09:44:38 +08:00
|
|
|
icon: const Icon(
|
|
|
|
Icons.keyboard_arrow_down,
|
|
|
|
color: Colors.white,
|
|
|
|
)),
|
2022-09-13 09:29:19 +08:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
chatModel.hideChatWindowOverlay();
|
|
|
|
chatModel.hideChatIconOverlay();
|
|
|
|
},
|
2023-05-29 09:44:38 +08:00
|
|
|
icon: const Icon(
|
|
|
|
Icons.close,
|
|
|
|
color: Colors.white,
|
|
|
|
))
|
2022-09-13 09:29:19 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-14 22:50:13 +08:00
|
|
|
Widget _buildDesktopAppBar(BuildContext context) {
|
2022-09-13 09:29:19 +08:00
|
|
|
return Container(
|
2022-10-14 22:50:13 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: Theme.of(context).hintColor.withOpacity(0.4)))),
|
|
|
|
height: 38,
|
2023-02-06 23:11:48 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
|
|
|
child: Obx(() => Opacity(
|
|
|
|
opacity: chatModel.isWindowFocus.value ? 1.0 : 0.4,
|
2023-02-06 08:54:21 +08:00
|
|
|
child: Row(children: [
|
|
|
|
Icon(Icons.chat_bubble_outline,
|
|
|
|
size: 20, color: Theme.of(context).colorScheme.primary),
|
|
|
|
SizedBox(width: 6),
|
|
|
|
Text(translate("Chat"))
|
2023-02-06 23:11:48 +08:00
|
|
|
])))),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(2),
|
|
|
|
child: ActionIcon(
|
|
|
|
message: 'Close',
|
|
|
|
icon: IconFont.close,
|
|
|
|
onTap: chatModel.hideChatWindowOverlay,
|
|
|
|
isClose: true,
|
|
|
|
boxSize: 32,
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
2022-09-13 09:29:19 +08:00
|
|
|
);
|
|
|
|
}
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
|
|
final GestureDragUpdateCallback onPanUpdate;
|
|
|
|
final Widget appBar;
|
|
|
|
|
|
|
|
const CustomAppBar(
|
|
|
|
{Key? key, required this.onPanUpdate, required this.appBar})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(onPanUpdate: onPanUpdate, child: appBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-09-13 09:29:19 +08:00
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// floating buttons of back/home/recent actions for android
|
|
|
|
class DraggableMobileActions extends StatelessWidget {
|
|
|
|
DraggableMobileActions(
|
2024-06-01 20:23:58 +08:00
|
|
|
{this.onBackPressed,
|
2022-05-02 16:02:49 +08:00
|
|
|
this.onRecentPressed,
|
|
|
|
this.onHomePressed,
|
2022-09-08 22:18:02 +08:00
|
|
|
this.onHidePressed,
|
2024-06-01 20:23:58 +08:00
|
|
|
required this.position,
|
2022-05-02 16:02:49 +08:00
|
|
|
required this.width,
|
2024-06-01 20:23:58 +08:00
|
|
|
required this.height,
|
|
|
|
required this.scale});
|
2022-05-02 16:02:49 +08:00
|
|
|
|
2024-06-01 20:23:58 +08:00
|
|
|
final double scale;
|
2024-06-23 11:06:47 +08:00
|
|
|
final DraggableKeyPosition position;
|
2022-05-02 16:02:49 +08:00
|
|
|
final double width;
|
|
|
|
final double height;
|
|
|
|
final VoidCallback? onBackPressed;
|
|
|
|
final VoidCallback? onHomePressed;
|
|
|
|
final VoidCallback? onRecentPressed;
|
2022-09-08 22:18:02 +08:00
|
|
|
final VoidCallback? onHidePressed;
|
2022-05-02 16:02:49 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Draggable(
|
|
|
|
position: position,
|
2024-06-01 20:23:58 +08:00
|
|
|
width: scale * width,
|
|
|
|
height: scale * height,
|
2022-05-02 16:02:49 +08:00
|
|
|
builder: (_, onPanUpdate) {
|
|
|
|
return GestureDetector(
|
|
|
|
onPanUpdate: onPanUpdate,
|
2022-09-08 22:18:02 +08:00
|
|
|
child: Card(
|
|
|
|
color: Colors.transparent,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: MyTheme.accent.withOpacity(0.4),
|
2024-06-01 20:23:58 +08:00
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(15 * scale))),
|
2022-09-08 22:18:02 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
2022-09-23 16:31:50 +08:00
|
|
|
color: Colors.white,
|
2022-09-08 22:18:02 +08:00
|
|
|
onPressed: onBackPressed,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2024-06-01 20:23:58 +08:00
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
iconSize: 24 * scale),
|
2022-09-08 22:18:02 +08:00
|
|
|
IconButton(
|
2022-09-23 16:31:50 +08:00
|
|
|
color: Colors.white,
|
2022-09-08 22:18:02 +08:00
|
|
|
onPressed: onHomePressed,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2024-06-01 20:23:58 +08:00
|
|
|
icon: const Icon(Icons.home),
|
|
|
|
iconSize: 24 * scale),
|
2022-09-08 22:18:02 +08:00
|
|
|
IconButton(
|
2022-09-23 16:31:50 +08:00
|
|
|
color: Colors.white,
|
2022-09-08 22:18:02 +08:00
|
|
|
onPressed: onRecentPressed,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2024-06-01 20:23:58 +08:00
|
|
|
icon: const Icon(Icons.more_horiz),
|
|
|
|
iconSize: 24 * scale),
|
2022-09-08 22:18:02 +08:00
|
|
|
const VerticalDivider(
|
|
|
|
width: 0,
|
|
|
|
thickness: 2,
|
|
|
|
indent: 10,
|
|
|
|
endIndent: 10,
|
|
|
|
),
|
|
|
|
IconButton(
|
2022-09-23 16:31:50 +08:00
|
|
|
color: Colors.white,
|
2022-09-08 22:18:02 +08:00
|
|
|
onPressed: onHidePressed,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2024-06-01 20:23:58 +08:00
|
|
|
icon: const Icon(Icons.keyboard_arrow_down),
|
|
|
|
iconSize: 24 * scale),
|
2022-09-08 22:18:02 +08:00
|
|
|
],
|
2022-05-02 16:02:49 +08:00
|
|
|
),
|
2022-09-08 22:18:02 +08:00
|
|
|
)));
|
2022-05-02 16:02:49 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-23 11:06:47 +08:00
|
|
|
class DraggableKeyPosition {
|
|
|
|
final String key;
|
|
|
|
Offset _pos;
|
|
|
|
late Debouncer<int> _debouncerStore;
|
|
|
|
DraggableKeyPosition(this.key)
|
|
|
|
: _pos = DraggablePositions.kInvalidDraggablePosition;
|
|
|
|
|
|
|
|
get pos => _pos;
|
|
|
|
|
|
|
|
_loadPosition(String k) {
|
|
|
|
final value = bind.getLocalFlutterOption(k: k);
|
|
|
|
if (value.isNotEmpty) {
|
|
|
|
final parts = value.split(',');
|
|
|
|
if (parts.length == 2) {
|
|
|
|
return Offset(double.parse(parts[0]), double.parse(parts[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DraggablePositions.kInvalidDraggablePosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
load() {
|
|
|
|
_pos = _loadPosition(key);
|
|
|
|
_debouncerStore = Debouncer<int>(const Duration(milliseconds: 500),
|
|
|
|
onChanged: (v) => _store(), initialValue: 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
update(Offset pos) {
|
|
|
|
_pos = pos;
|
|
|
|
_triggerStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust position to keep it in the screen
|
|
|
|
// Only used for desktop and web desktop
|
|
|
|
tryAdjust(double w, double h, double scale) {
|
|
|
|
final size = MediaQuery.of(Get.context!).size;
|
|
|
|
w = w * scale;
|
|
|
|
h = h * scale;
|
|
|
|
double x = _pos.dx;
|
|
|
|
double y = _pos.dy;
|
|
|
|
if (x + w > size.width) {
|
|
|
|
x = size.width - w;
|
|
|
|
}
|
|
|
|
final tabBarHeight = isDesktop ? kDesktopRemoteTabBarHeight : 0;
|
|
|
|
if (y + h > (size.height - tabBarHeight)) {
|
|
|
|
y = size.height - tabBarHeight - h;
|
|
|
|
}
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (x != _pos.dx || y != _pos.dy) {
|
|
|
|
update(Offset(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isInvalid() {
|
|
|
|
return _pos == DraggablePositions.kInvalidDraggablePosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
_triggerStore() => _debouncerStore.value = _debouncerStore.value + 1;
|
|
|
|
_store() {
|
|
|
|
bind.setLocalFlutterOption(k: key, v: '${_pos.dx},${_pos.dy}');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DraggablePositions {
|
|
|
|
static const kChatWindow = 'draggablePositionChat';
|
|
|
|
static const kMobileActions = 'draggablePositionMobile';
|
|
|
|
static const kIOSDraggable = 'draggablePositionIOS';
|
|
|
|
|
|
|
|
static const kInvalidDraggablePosition = Offset(-999999, -999999);
|
|
|
|
final chatWindow = DraggableKeyPosition(kChatWindow);
|
|
|
|
final mobileActions = DraggableKeyPosition(kMobileActions);
|
|
|
|
final iOSDraggable = DraggableKeyPosition(kIOSDraggable);
|
|
|
|
|
|
|
|
load() {
|
|
|
|
chatWindow.load();
|
|
|
|
mobileActions.load();
|
|
|
|
iOSDraggable.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DraggablePositions draggablePositions = DraggablePositions();
|
|
|
|
|
2022-05-02 16:02:49 +08:00
|
|
|
class Draggable extends StatefulWidget {
|
2024-06-01 20:23:58 +08:00
|
|
|
Draggable(
|
2022-09-13 09:29:19 +08:00
|
|
|
{Key? key,
|
|
|
|
this.checkKeyboard = false,
|
2022-05-02 16:02:49 +08:00
|
|
|
this.checkScreenSize = false,
|
2024-06-01 20:23:58 +08:00
|
|
|
required this.position,
|
2022-05-02 16:02:49 +08:00
|
|
|
required this.width,
|
|
|
|
required this.height,
|
2023-09-04 04:15:48 +08:00
|
|
|
this.chatModel,
|
2022-09-13 09:29:19 +08:00
|
|
|
required this.builder})
|
|
|
|
: super(key: key);
|
2022-05-02 16:02:49 +08:00
|
|
|
|
|
|
|
final bool checkKeyboard;
|
|
|
|
final bool checkScreenSize;
|
2024-06-23 11:06:47 +08:00
|
|
|
final DraggableKeyPosition position;
|
2022-05-02 16:02:49 +08:00
|
|
|
final double width;
|
|
|
|
final double height;
|
2023-09-04 04:15:48 +08:00
|
|
|
final ChatModel? chatModel;
|
2022-05-02 16:02:49 +08:00
|
|
|
final Widget Function(BuildContext, GestureDragUpdateCallback) builder;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _DraggableState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DraggableState extends State<Draggable> {
|
2023-09-04 04:15:48 +08:00
|
|
|
late ChatModel? _chatModel;
|
2022-05-02 16:02:49 +08:00
|
|
|
bool _keyboardVisible = false;
|
|
|
|
double _saveHeight = 0;
|
|
|
|
double _lastBottomHeight = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2023-09-04 23:17:45 +08:00
|
|
|
_chatModel = widget.chatModel;
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
2024-06-23 11:06:47 +08:00
|
|
|
get position => widget.position.pos;
|
2024-06-01 20:23:58 +08:00
|
|
|
|
2022-05-02 16:02:49 +08:00
|
|
|
void onPanUpdate(DragUpdateDetails d) {
|
|
|
|
final offset = d.delta;
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
double x = 0;
|
|
|
|
double y = 0;
|
|
|
|
|
2024-06-01 20:23:58 +08:00
|
|
|
if (position.dx + offset.dx + widget.width > size.width) {
|
2022-05-02 16:02:49 +08:00
|
|
|
x = size.width - widget.width;
|
2024-06-01 20:23:58 +08:00
|
|
|
} else if (position.dx + offset.dx < 0) {
|
2022-05-02 16:02:49 +08:00
|
|
|
x = 0;
|
|
|
|
} else {
|
2024-06-01 20:23:58 +08:00
|
|
|
x = position.dx + offset.dx;
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
2024-06-01 20:23:58 +08:00
|
|
|
if (position.dy + offset.dy + widget.height > size.height) {
|
2022-05-02 16:02:49 +08:00
|
|
|
y = size.height - widget.height;
|
2024-06-01 20:23:58 +08:00
|
|
|
} else if (position.dy + offset.dy < 0) {
|
2022-05-02 16:02:49 +08:00
|
|
|
y = 0;
|
|
|
|
} else {
|
2024-06-01 20:23:58 +08:00
|
|
|
y = position.dy + offset.dy;
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
setState(() {
|
2024-06-23 11:06:47 +08:00
|
|
|
widget.position.update(Offset(x, y));
|
2022-05-02 16:02:49 +08:00
|
|
|
});
|
2024-06-01 20:23:58 +08:00
|
|
|
_chatModel?.setChatWindowPosition(position);
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
checkScreenSize() {}
|
|
|
|
|
|
|
|
checkKeyboard() {
|
|
|
|
final bottomHeight = MediaQuery.of(context).viewInsets.bottom;
|
|
|
|
final currentVisible = bottomHeight != 0;
|
|
|
|
|
|
|
|
// save
|
|
|
|
if (!_keyboardVisible && currentVisible) {
|
2024-06-01 20:23:58 +08:00
|
|
|
_saveHeight = position.dy;
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// reset
|
|
|
|
if (_lastBottomHeight > 0 && bottomHeight == 0) {
|
|
|
|
setState(() {
|
2024-06-23 11:06:47 +08:00
|
|
|
widget.position.update(Offset(position.dx, _saveHeight));
|
2022-05-02 16:02:49 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// onKeyboardVisible
|
|
|
|
if (_keyboardVisible && currentVisible) {
|
|
|
|
final sumHeight = bottomHeight + widget.height;
|
|
|
|
final contextHeight = MediaQuery.of(context).size.height;
|
2024-06-01 20:23:58 +08:00
|
|
|
if (sumHeight + position.dy > contextHeight) {
|
2022-05-02 16:02:49 +08:00
|
|
|
final y = contextHeight - sumHeight;
|
|
|
|
setState(() {
|
2024-06-23 11:06:47 +08:00
|
|
|
widget.position.update(Offset(position.dx, y));
|
2022-05-02 16:02:49 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyboardVisible = currentVisible;
|
|
|
|
_lastBottomHeight = bottomHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (widget.checkKeyboard) {
|
|
|
|
checkKeyboard();
|
|
|
|
}
|
2023-02-06 08:54:21 +08:00
|
|
|
if (widget.checkScreenSize) {
|
2022-05-02 16:02:49 +08:00
|
|
|
checkScreenSize();
|
|
|
|
}
|
2023-02-06 08:54:21 +08:00
|
|
|
return Stack(children: [
|
|
|
|
Positioned(
|
2024-06-01 20:23:58 +08:00
|
|
|
top: position.dy,
|
|
|
|
left: position.dx,
|
2023-02-06 08:54:21 +08:00
|
|
|
width: widget.width,
|
|
|
|
height: widget.height,
|
|
|
|
child: widget.builder(context, onPanUpdate))
|
|
|
|
]);
|
2022-05-02 16:02:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-27 23:05:11 +08:00
|
|
|
|
2023-09-01 14:38:33 +08:00
|
|
|
class IOSDraggable extends StatefulWidget {
|
2023-10-27 15:44:07 +08:00
|
|
|
const IOSDraggable(
|
|
|
|
{Key? key,
|
|
|
|
this.chatModel,
|
2024-06-23 11:06:47 +08:00
|
|
|
required this.position,
|
2023-10-27 15:44:07 +08:00
|
|
|
required this.width,
|
|
|
|
required this.height,
|
|
|
|
required this.builder})
|
|
|
|
: super(key: key);
|
2023-09-01 14:38:33 +08:00
|
|
|
|
2024-06-23 11:06:47 +08:00
|
|
|
final DraggableKeyPosition position;
|
2023-09-04 04:15:48 +08:00
|
|
|
final ChatModel? chatModel;
|
2023-09-01 14:38:33 +08:00
|
|
|
final double width;
|
|
|
|
final double height;
|
|
|
|
final Widget Function(BuildContext) builder;
|
|
|
|
|
|
|
|
@override
|
2024-02-12 21:39:19 +08:00
|
|
|
IOSDraggableState createState() => IOSDraggableState();
|
2023-09-01 14:38:33 +08:00
|
|
|
}
|
|
|
|
|
2024-02-12 21:39:19 +08:00
|
|
|
class IOSDraggableState extends State<IOSDraggable> {
|
2023-09-04 23:17:45 +08:00
|
|
|
late ChatModel? _chatModel;
|
|
|
|
late double _width;
|
|
|
|
late double _height;
|
|
|
|
bool _keyboardVisible = false;
|
|
|
|
double _saveHeight = 0;
|
|
|
|
double _lastBottomHeight = 0;
|
2023-09-01 14:38:33 +08:00
|
|
|
|
2023-09-04 23:17:45 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_chatModel = widget.chatModel;
|
|
|
|
_width = widget.width;
|
|
|
|
_height = widget.height;
|
|
|
|
}
|
|
|
|
|
2024-06-24 22:56:13 +08:00
|
|
|
DraggableKeyPosition get position => widget.position;
|
2024-06-23 11:06:47 +08:00
|
|
|
|
2023-09-05 20:28:22 +08:00
|
|
|
checkKeyboard() {
|
|
|
|
final bottomHeight = MediaQuery.of(context).viewInsets.bottom;
|
|
|
|
final currentVisible = bottomHeight != 0;
|
2023-09-04 23:17:45 +08:00
|
|
|
|
2023-09-05 20:28:22 +08:00
|
|
|
// save
|
2023-09-04 23:17:45 +08:00
|
|
|
if (!_keyboardVisible && currentVisible) {
|
2024-06-24 22:56:13 +08:00
|
|
|
_saveHeight = position.pos.dy;
|
2023-09-05 20:28:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// reset
|
|
|
|
if (_lastBottomHeight > 0 && bottomHeight == 0) {
|
2023-09-04 23:17:45 +08:00
|
|
|
setState(() {
|
2024-06-24 22:56:13 +08:00
|
|
|
position.update(Offset(position.pos.dx, _saveHeight));
|
2023-09-04 23:17:45 +08:00
|
|
|
});
|
2023-09-05 20:28:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// onKeyboardVisible
|
|
|
|
if (_keyboardVisible && currentVisible) {
|
|
|
|
final sumHeight = bottomHeight + _height;
|
2023-09-04 23:17:45 +08:00
|
|
|
final contextHeight = MediaQuery.of(context).size.height;
|
2024-06-24 22:56:13 +08:00
|
|
|
if (sumHeight + position.pos.dy > contextHeight) {
|
2023-09-04 23:17:45 +08:00
|
|
|
final y = contextHeight - sumHeight;
|
|
|
|
setState(() {
|
2024-06-24 22:56:13 +08:00
|
|
|
position.update(Offset(position.pos.dx, y));
|
2023-09-04 23:17:45 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyboardVisible = currentVisible;
|
2023-09-05 20:28:22 +08:00
|
|
|
_lastBottomHeight = bottomHeight;
|
2023-09-04 23:17:45 +08:00
|
|
|
}
|
2023-09-01 14:38:33 +08:00
|
|
|
|
2023-10-27 15:44:07 +08:00
|
|
|
@override
|
2023-09-01 14:38:33 +08:00
|
|
|
Widget build(BuildContext context) {
|
2023-09-05 20:28:22 +08:00
|
|
|
checkKeyboard();
|
2023-09-01 14:38:33 +08:00
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
Positioned(
|
2024-06-24 22:56:13 +08:00
|
|
|
left: position.pos.dx,
|
|
|
|
top: position.pos.dy,
|
2023-09-01 14:38:33 +08:00
|
|
|
child: GestureDetector(
|
|
|
|
onPanUpdate: (details) {
|
|
|
|
setState(() {
|
2024-06-24 22:56:13 +08:00
|
|
|
position.update(position.pos + details.delta);
|
2023-09-01 14:38:33 +08:00
|
|
|
});
|
2024-06-24 22:56:13 +08:00
|
|
|
_chatModel?.setChatWindowPosition(position.pos);
|
2023-09-01 14:38:33 +08:00
|
|
|
},
|
|
|
|
child: Material(
|
2023-10-27 15:44:07 +08:00
|
|
|
child: Container(
|
|
|
|
width: _width,
|
|
|
|
height: _height,
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(border: Border.all(color: MyTheme.border)),
|
|
|
|
child: widget.builder(context),
|
2023-09-01 14:38:33 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:05:11 +08:00
|
|
|
class QualityMonitor extends StatelessWidget {
|
|
|
|
final QualityMonitorModel qualityMonitorModel;
|
|
|
|
QualityMonitor(this.qualityMonitorModel);
|
|
|
|
|
2023-02-01 19:36:36 +08:00
|
|
|
Widget _row(String info, String? value, {Color? rightColor}) {
|
2023-01-30 21:40:13 +08:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 8,
|
|
|
|
child: AutoSizeText(info,
|
2023-03-13 08:17:16 +08:00
|
|
|
style: TextStyle(color: Color.fromARGB(255, 210, 210, 210)),
|
2023-01-30 21:40:13 +08:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
maxLines: 1)),
|
|
|
|
Spacer(flex: 1),
|
|
|
|
Expanded(
|
|
|
|
flex: 8,
|
|
|
|
child: AutoSizeText(value ?? '',
|
2023-02-01 19:36:36 +08:00
|
|
|
style: TextStyle(color: rightColor ?? Colors.white),
|
|
|
|
maxLines: 1)),
|
2023-01-30 21:40:13 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:05:11 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => ChangeNotifierProvider.value(
|
|
|
|
value: qualityMonitorModel,
|
|
|
|
child: Consumer<QualityMonitorModel>(
|
2023-01-30 21:40:13 +08:00
|
|
|
builder: (context, qualityMonitorModel, child) => qualityMonitorModel
|
|
|
|
.show
|
|
|
|
? Container(
|
|
|
|
constraints: BoxConstraints(maxWidth: 200),
|
|
|
|
padding: const EdgeInsets.all(8),
|
2023-03-13 08:17:16 +08:00
|
|
|
color: MyTheme.canvasColor.withAlpha(150),
|
2023-01-30 21:40:13 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2023-02-01 19:36:36 +08:00
|
|
|
_row("Speed", qualityMonitorModel.data.speed ?? '-'),
|
|
|
|
_row("FPS", qualityMonitorModel.data.fps ?? '-'),
|
2024-06-22 09:39:02 +08:00
|
|
|
// let delay be 0 if fps is 0
|
2023-01-30 21:40:13 +08:00
|
|
|
_row(
|
2024-06-22 09:39:02 +08:00
|
|
|
"Delay",
|
|
|
|
"${qualityMonitorModel.data.delay == null ? '-' : (qualityMonitorModel.data.fps ?? "").replaceAll(' ', '').replaceAll('0', '').isEmpty ? 0 : qualityMonitorModel.data.delay}ms",
|
2023-02-01 19:36:36 +08:00
|
|
|
rightColor: Colors.green),
|
2023-01-30 21:40:13 +08:00
|
|
|
_row("Target Bitrate",
|
2023-02-01 19:36:36 +08:00
|
|
|
"${qualityMonitorModel.data.targetBitrate ?? '-'}kb"),
|
|
|
|
_row(
|
|
|
|
"Codec", qualityMonitorModel.data.codecFormat ?? '-'),
|
2023-10-27 15:44:07 +08:00
|
|
|
_row("Chroma", qualityMonitorModel.data.chroma ?? '-'),
|
2023-01-30 21:40:13 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink()));
|
2022-09-27 23:05:11 +08:00
|
|
|
}
|
2023-02-06 23:11:48 +08:00
|
|
|
|
2023-02-08 21:01:15 +08:00
|
|
|
class BlockableOverlayState extends OverlayKeyState {
|
2023-02-06 23:11:48 +08:00
|
|
|
final _middleBlocked = false.obs;
|
|
|
|
|
|
|
|
VoidCallback? onMiddleBlockedClick; // to-do use listener
|
|
|
|
|
|
|
|
RxBool get middleBlocked => _middleBlocked;
|
|
|
|
|
|
|
|
void addMiddleBlockedListener(void Function(bool) cb) {
|
|
|
|
_middleBlocked.listen(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMiddleBlocked(bool blocked) {
|
|
|
|
if (blocked != _middleBlocked.value) {
|
|
|
|
_middleBlocked.value = blocked;
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 09:51:41 +08:00
|
|
|
|
|
|
|
void applyFfi(FFI ffi) {
|
|
|
|
ffi.dialogManager.setOverlayState(this);
|
|
|
|
ffi.chatModel.setOverlayState(this);
|
|
|
|
// make remote page penetrable automatically, effective for chat over remote
|
|
|
|
onMiddleBlockedClick = () {
|
|
|
|
setMiddleBlocked(false);
|
|
|
|
};
|
|
|
|
}
|
2023-02-06 23:11:48 +08:00
|
|
|
}
|
|
|
|
|
2023-02-08 21:01:15 +08:00
|
|
|
class BlockableOverlay extends StatelessWidget {
|
2023-02-06 23:11:48 +08:00
|
|
|
final Widget underlying;
|
|
|
|
final List<OverlayEntry>? upperLayer;
|
|
|
|
|
2023-02-08 21:01:15 +08:00
|
|
|
final BlockableOverlayState state;
|
2023-02-06 23:11:48 +08:00
|
|
|
|
2023-02-08 21:01:15 +08:00
|
|
|
BlockableOverlay(
|
2023-02-06 23:11:48 +08:00
|
|
|
{required this.underlying, required this.state, this.upperLayer});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final initialEntries = [
|
|
|
|
OverlayEntry(builder: (_) => underlying),
|
|
|
|
|
|
|
|
/// middle layer
|
|
|
|
OverlayEntry(
|
|
|
|
builder: (context) => Obx(() => Listener(
|
|
|
|
onPointerDown: (_) {
|
|
|
|
state.onMiddleBlockedClick?.call();
|
|
|
|
},
|
|
|
|
child: Container(
|
2023-02-08 21:05:11 +08:00
|
|
|
color:
|
|
|
|
state.middleBlocked.value ? Colors.transparent : null)))),
|
2023-02-06 23:11:48 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
if (upperLayer != null) {
|
|
|
|
initialEntries.addAll(upperLayer!);
|
|
|
|
}
|
|
|
|
|
2023-02-08 21:01:15 +08:00
|
|
|
/// set key
|
|
|
|
return Overlay(key: state.key, initialEntries: initialEntries);
|
2023-02-06 23:11:48 +08:00
|
|
|
}
|
|
|
|
}
|