mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can move window
This commit is contained in:
		@@ -1,10 +1,13 @@
 | 
				
			|||||||
import 'package:comunic/ui/screens/call_screen.dart';
 | 
					import 'package:comunic/ui/screens/call_screen.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/ui/widgets/tablet_mode/calls/calls_area.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Call window widget
 | 
					/// Call window widget
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// @author Pierre HUBERT
 | 
					/// @author Pierre HUBERT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const _WindowSize = Size(500, 200);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CallWindowWidget extends StatefulWidget {
 | 
					class CallWindowWidget extends StatefulWidget {
 | 
				
			||||||
  final int convID;
 | 
					  final int convID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,14 +22,59 @@ class CallWindowWidget extends StatefulWidget {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class _CallWindowWidgetState extends State<CallWindowWidget> {
 | 
					class _CallWindowWidgetState extends State<CallWindowWidget> {
 | 
				
			||||||
 | 
					  double _left, _top;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  void didChangeDependencies() {
 | 
				
			||||||
 | 
					    super.didChangeDependencies();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Initialize window coordinates
 | 
				
			||||||
 | 
					    _top = 10;
 | 
				
			||||||
 | 
					    _left = MediaQuery.of(context).size.width - 10 - _WindowSize.width;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Widget build(BuildContext context) {
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
    return Positioned(
 | 
					    return Positioned(
 | 
				
			||||||
      width: 500,
 | 
					      width: _WindowSize.width,
 | 
				
			||||||
      height: 200,
 | 
					      height: _WindowSize.height,
 | 
				
			||||||
      right: 10,
 | 
					      left: _left,
 | 
				
			||||||
      top: 10,
 | 
					      top: _top,
 | 
				
			||||||
      child: Card(child: CallScreen(convID: widget.convID)),
 | 
					      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<CallsAreaState>()
 | 
				
			||||||
 | 
					        .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(() {});
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user