Skip to content

Commit

Permalink
Merge pull request #242 from yakforward-ou/widgetweaver
Browse files Browse the repository at this point in the history
[yak_flutter] add EdgePositioned
  • Loading branch information
iapicca authored Apr 20, 2024
2 parents 9d8939c + ea43e2d commit 8b467ae
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/yak_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 3.0.1
- add `EdgePositioned`

### 3.0.0
- rework due to yak_result v3

Expand Down
1 change: 1 addition & 0 deletions packages/yak_flutter/lib/src/widgets/all.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'preferred_size_themed.dart';
export 'edge_positioned.dart';
115 changes: 115 additions & 0 deletions packages/yak_flutter/lib/src/widgets/edge_positioned.dart
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/yak_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 8b467ae

Please sign in to comment.