-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
382 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"dart.flutterSdkPath": "C:\\Users\\ping\\.puro\\envs\\beta\\flutter", | ||
"dart.sdkPath": "C:\\Users\\ping\\.puro\\envs\\beta\\flutter\\bin\\cache\\dart-sdk" | ||
} |
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 @@ | ||
export 'package:boxy/redirect_pointer.dart'; |
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 @@ | ||
export 'src/scale.dart'; |
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,78 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/rendering.dart'; | ||
|
||
class RedirectPointer extends SingleChildRenderObjectWidget { | ||
const RedirectPointer({ | ||
super.key, | ||
super.child, | ||
this.above = const [], | ||
this.below = const [], | ||
}); | ||
|
||
final List<GlobalKey> below; | ||
final List<GlobalKey> above; | ||
|
||
@override | ||
RenderRedirectPointer createRenderObject(BuildContext context) { | ||
return RenderRedirectPointer(below: below, above: above); | ||
} | ||
|
||
@override | ||
void updateRenderObject( | ||
BuildContext context, | ||
RenderRedirectPointer renderObject, | ||
) { | ||
renderObject | ||
..below = below | ||
..above = above; | ||
} | ||
} | ||
|
||
class RenderRedirectPointer extends RenderProxyBox { | ||
RenderRedirectPointer({ | ||
RenderBox? child, | ||
this.below = const [], | ||
this.above = const [], | ||
}) : super(child); | ||
|
||
List<GlobalKey> below; | ||
List<GlobalKey> above; | ||
|
||
@override | ||
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { | ||
for (final key in above.reversed) { | ||
final child = key.currentContext?.findRenderObject() as RenderBox?; | ||
if (child != null) { | ||
final hit = result.addWithPaintTransform( | ||
transform: child.getTransformTo(this), | ||
position: position, | ||
hitTest: (result, position) { | ||
return child.hitTest(result, position: position); | ||
}, | ||
); | ||
if (hit) { | ||
return true; | ||
} | ||
} | ||
} | ||
if (super.hitTestChildren(result, position: position)) { | ||
return true; | ||
} | ||
for (final key in below.reversed) { | ||
final child = key.currentContext?.findRenderObject() as RenderBox?; | ||
if (child != null) { | ||
final hit = result.addWithPaintTransform( | ||
transform: child.getTransformTo(this), | ||
position: position, | ||
hitTest: (result, position) { | ||
return child.hitTest(result, position: position); | ||
}, | ||
); | ||
if (hit) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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,42 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../boxy.dart'; | ||
|
||
class Scale extends StatelessWidget { | ||
const Scale({ | ||
super.key, | ||
required this.child, | ||
required this.scale, | ||
}); | ||
|
||
final Widget child; | ||
final double scale; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CustomBoxy( | ||
delegate: _ScaleBoxy(scale), | ||
children: [child], | ||
); | ||
} | ||
} | ||
|
||
class _ScaleBoxy extends BoxyDelegate { | ||
_ScaleBoxy(this.scale); | ||
|
||
final double scale; | ||
|
||
@override | ||
bool shouldRelayout(_ScaleBoxy oldDelegate) => scale != oldDelegate.scale; | ||
|
||
@override | ||
Size layout() { | ||
final child = children.single; | ||
if (scale == 0 || !scale.isFinite) { | ||
child.layout(BoxConstraints.tight(Size.zero)); | ||
return Size.zero; | ||
} | ||
child.setTransform(Matrix4.identity()..scale(scale)); | ||
return child.layout(constraints / scale) * scale; | ||
} | ||
} |
Oops, something went wrong.