From ef186f79d2342cc010fded90aa538f48a14d2ccf Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 10 May 2020 14:09:44 +0200 Subject: [PATCH] Can move window --- .../tablet_mode/calls/call_window_widget.dart | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/ui/widgets/tablet_mode/calls/call_window_widget.dart b/lib/ui/widgets/tablet_mode/calls/call_window_widget.dart index f37e31b..64574bd 100644 --- a/lib/ui/widgets/tablet_mode/calls/call_window_widget.dart +++ b/lib/ui/widgets/tablet_mode/calls/call_window_widget.dart @@ -1,10 +1,13 @@ import 'package:comunic/ui/screens/call_screen.dart'; +import 'package:comunic/ui/widgets/tablet_mode/calls/calls_area.dart'; import 'package:flutter/material.dart'; /// Call window widget /// /// @author Pierre HUBERT +const _WindowSize = Size(500, 200); + class CallWindowWidget extends StatefulWidget { final int convID; @@ -19,14 +22,59 @@ class CallWindowWidget extends StatefulWidget { } class _CallWindowWidgetState extends State { + double _left, _top; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + // Initialize window coordinates + _top = 10; + _left = MediaQuery.of(context).size.width - 10 - _WindowSize.width; + } + @override Widget build(BuildContext context) { return Positioned( - width: 500, - height: 200, - right: 10, - top: 10, - child: Card(child: CallScreen(convID: widget.convID)), + width: _WindowSize.width, + height: _WindowSize.height, + left: _left, + top: _top, + child: Draggable( + child: Card(child: CallScreen(convID: widget.convID)), + feedback: Container( + width: _WindowSize.width, + height: _WindowSize.height, + color: Colors.red, + ), + onDragEnd: _moveEnd, + ), ); } + + /// Compute new window position + void _moveEnd(DraggableDetails details) { + // Determine the limits of containing stack + RenderBox renderBox = context + .findAncestorStateOfType() + .context + .findRenderObject(); + final size = renderBox.size; + final offset = renderBox.localToGlobal(Offset.zero); + + // Determine new window position + _top = details.offset.dy - offset.dy; + _left = details.offset.dx - offset.dx; + + // Force the window to appear completely on the screen + if (_top + _WindowSize.height >= size.height) + _top = size.height - _WindowSize.height; + if (_left + _WindowSize.width >= size.width) + _left = size.width - _WindowSize.width; + + if (_top < 0) _top = 0; + if (_left < 0) _left = 0; + + setState(() {}); + } }