diff --git a/packages/yak_flutter/CHANGELOG.md b/packages/yak_flutter/CHANGELOG.md index e6427b17..79de3d73 100644 --- a/packages/yak_flutter/CHANGELOG.md +++ b/packages/yak_flutter/CHANGELOG.md @@ -1,3 +1,6 @@ +### 3.0.1 +- add `EdgePositioned` + ### 3.0.0 - rework due to yak_result v3 diff --git a/packages/yak_flutter/lib/src/widgets/all.dart b/packages/yak_flutter/lib/src/widgets/all.dart index 9b1ae05f..007c96d6 100644 --- a/packages/yak_flutter/lib/src/widgets/all.dart +++ b/packages/yak_flutter/lib/src/widgets/all.dart @@ -1 +1,2 @@ export 'preferred_size_themed.dart'; +export 'edge_positioned.dart'; diff --git a/packages/yak_flutter/lib/src/widgets/edge_positioned.dart b/packages/yak_flutter/lib/src/widgets/edge_positioned.dart new file mode 100644 index 00000000..9bc6ed70 --- /dev/null +++ b/packages/yak_flutter/lib/src/widgets/edge_positioned.dart @@ -0,0 +1,115 @@ +import 'package:flutter/widgets.dart'; + +/// a positioned widget that "starts" from one of the edges of the screen +/// inspired by `https://gist.github.com/aoatmon/ee4a35747b6826b73aa02aee34963f10` + +abstract class EdgePositioned extends Positioned { + final EdgeInsets padding; + final double dimension; + const EdgePositioned({ + required super.child, + required this.dimension, + required this.padding, + super.key, + }); + + const factory EdgePositioned.top({ + required Widget child, + double dimension, + EdgeInsets padding, + Key key, + }) = _EdgePositioneTop; + + const factory EdgePositioned.bottom({ + required Widget child, + double dimension, + EdgeInsets padding, + Key key, + }) = _EdgePositioneBottom; + + const factory EdgePositioned.left({ + required Widget child, + double dimension, + EdgeInsets padding, + Key key, + }) = _EdgePositioneLeft; + + const factory EdgePositioned.right({ + required Widget child, + double dimension, + EdgeInsets padding, + Key key, + }) = _EdgePositioneRight; +} + +class _EdgePositioneBottom extends EdgePositioned { + const _EdgePositioneBottom({ + required super.child, + super.dimension = 0, + super.padding = EdgeInsets.zero, + super.key, + }); + + @override + double get left => padding.left; + @override + double get right => padding.right; + @override + double get bottom => padding.bottom; + @override + double get height => dimension - padding.vertical; +} + +class _EdgePositioneTop extends EdgePositioned { + const _EdgePositioneTop({ + required super.child, + super.dimension = 0, + super.padding = EdgeInsets.zero, + super.key, + }); + + @override + double get left => padding.left; + @override + double get right => padding.right; + @override + double get top => padding.top; + @override + double get height => dimension - padding.vertical; +} + +class _EdgePositioneLeft extends EdgePositioned { + const _EdgePositioneLeft({ + required super.child, + super.dimension = 0, + super.padding = EdgeInsets.zero, + super.key, + }); + + @override + double get left => padding.left; + @override + double get top => padding.top; + @override + double get bottom => padding.bottom; + @override + double get width => dimension - padding.horizontal; +} + +class _EdgePositioneRight extends EdgePositioned { + const _EdgePositioneRight({ + required super.child, + super.dimension = 0, + super.padding = EdgeInsets.zero, + super.key, + }); + + @override + double get right => padding.right; + @override + double get top => padding.top; + @override + double get bottom => padding.bottom; + @override + double get width => dimension - padding.horizontal; +} diff --git a/packages/yak_flutter/lib/src/widgets/preferred_size_themed.dart b/packages/yak_flutter/lib/src/widgets/preferred_size_themed.dart index 13710bbb..74b4914c 100644 --- a/packages/yak_flutter/lib/src/widgets/preferred_size_themed.dart +++ b/packages/yak_flutter/lib/src/widgets/preferred_size_themed.dart @@ -11,7 +11,7 @@ class PreferredSizeWidgetThemed extends StatelessWidget super.key, }); @override - Widget build(BuildContext context) => Theme(data: data, child: child); + Widget build(context) => Theme(data: data, child: child); @override Size get preferredSize => child.preferredSize; diff --git a/packages/yak_flutter/pubspec.yaml b/packages/yak_flutter/pubspec.yaml index 73a2463f..00c6b001 100644 --- a/packages/yak_flutter/pubspec.yaml +++ b/packages/yak_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: yak_flutter description: A collection of tools and extensions for Flutter. -version: 3.0.0 +version: 3.0.1 homepage: https://github.com/yakforward-ou/yak_packages environment: