-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor draggable feature for dialogs (issue #23)
- Removed isDraggable property from PositionedDialog and related usage in positioned_dialog_basic_usage.dart - Introduced FreePositioned widget to handle draggable functionality - Added draggable method in EasyDialogsController to apply draggable decoration - Updated PositionedDialog to use Align widget instead of _FreePositioned - Updated tests to cover new draggable feature - Updated CHANGELOG.md to reflect changes
- Loading branch information
1 parent
7fd8cb0
commit e6d1f32
Showing
8 changed files
with
152 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
class FreePositioned extends StatefulWidget { | ||
final Widget child; | ||
|
||
const FreePositioned({required this.child}); | ||
|
||
@override | ||
State<FreePositioned> createState() => _FreePositionedState(); | ||
} | ||
|
||
class _FreePositionedState extends State<FreePositioned> { | ||
var _x = 0.0; | ||
var _y = 0.0; | ||
AlignmentGeometry? _alignment; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final screenSize = MediaQuery.sizeOf(context); | ||
|
||
return Stack( | ||
children: [ | ||
Positioned( | ||
left: _x, | ||
top: _y, | ||
child: GestureDetector( | ||
onPanUpdate: (details) => setState( | ||
() { | ||
_x += details.delta.dx; | ||
_y += details.delta.dy; | ||
}, | ||
), | ||
child: ConstrainedBox( | ||
constraints: BoxConstraints( | ||
maxWidth: screenSize.width, | ||
maxHeight: screenSize.height, | ||
), | ||
// Not the best approach to apply alignment but it works for now, | ||
// need to be reworked in the future | ||
child: _alignment == null | ||
? widget.child | ||
: Align( | ||
alignment: _alignment!, | ||
child: widget.child, | ||
), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
void didChangeDependencies() { | ||
super.didChangeDependencies(); | ||
|
||
_alignment = context.findAncestorWidgetOfExactType<Align>()?.alignment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_easy_dialogs/src/core/widget/free_positioned.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('drag and position changes', (widgetTester) async { | ||
final key = GlobalKey(); | ||
final widget = Container( | ||
height: 100, | ||
width: 100, | ||
color: Colors.red, | ||
key: key, | ||
); | ||
await widgetTester.pumpWidget( | ||
MaterialApp( | ||
home: FreePositioned(child: widget), | ||
), | ||
); | ||
|
||
expect(find.byKey(key), findsOneWidget); | ||
|
||
final box = key.currentContext!.findRenderObject() as RenderBox; | ||
final positionBeforeDrag = box.localToGlobal(Offset.zero); | ||
|
||
await widgetTester.drag(find.byKey(key), const Offset(10, 10)); | ||
await widgetTester.pumpAndSettle(); | ||
|
||
final positionAfterDrag = box.localToGlobal(Offset.zero); | ||
|
||
expect(positionBeforeDrag, isNot(equals(positionAfterDrag))); | ||
}); | ||
} |