- Notifications
You must be signed in to change notification settings - Fork29.3k
Extend EdgeInsetsGeometry with Utility Methods: add EdgeInsets.some and EdgeInsets.except constructors#176507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Mohamed-7018 wants to merge6 commits intoflutter:masterChoose a base branch fromMohamed-7018:edge-insets-some-with-exceptSides
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+285 −11
Open
Changes from1 commit
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
71a39e8
framework: add EdgeInsets.some and EdgeInsets.except* constructors
Mohamed-70188f930dd
running dart format
Mohamed-70181606b12
chore: update lockfiles after pub get
Mohamed-701840719ae
Merge branch 'master' into edge-insets-some-with-exceptSides
Mohamed-7018c1fbc73
fix linux analyze
Mohamed-70189acf764
Merge branch 'master' into edge-insets-some-with-exceptSides
Mohamed-7018File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
149 changes: 149 additions & 0 deletionspackages/flutter/lib/src/painting/edge_insets.dart
This file contains hidden or 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 |
---|---|---|
@@ -40,6 +40,22 @@ abstract class EdgeInsetsGeometry { | ||
const factory EdgeInsetsGeometry.only({double left, double right, double top, double bottom}) = | ||
EdgeInsets.only; | ||
/// Creates [EdgeInsets] with all sides equal to [rest], | ||
/// but allows overriding individual sides. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// EdgeInsetsGeometry.some(rest: 16, left: 8, top: 0); | ||
/// ``` | ||
/// Results in: left = 8, top = 0, right = 16, bottom = 16 | ||
const factory EdgeInsetsGeometry.some({ | ||
double rest, | ||
Mohamed-7018 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
double? left, | ||
double? top, | ||
double? right, | ||
double? bottom, | ||
}) = EdgeInsets.some; | ||
/// Creates [EdgeInsetsDirectional] with only the given values non-zero. | ||
const factory EdgeInsetsGeometry.directional({ | ||
double start, | ||
@@ -70,6 +86,20 @@ abstract class EdgeInsetsGeometry { | ||
const factory EdgeInsetsGeometry.fromSTEB(double start, double top, double end, double bottom) = | ||
EdgeInsetsDirectional.fromSTEB; | ||
/// Creates insets where all sides are [value] except [top]. | ||
Mohamed-7018 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const factory EdgeInsetsGeometry.exceptTop(double value, [double top]) = EdgeInsets.exceptTop; | ||
/// Creates insets where all sides are [value] except [bottom]. | ||
const factory EdgeInsetsGeometry.exceptBottom(double value, [double bottom]) = | ||
EdgeInsets.exceptBottom; | ||
/// Creates insets where all sides are [value] except [left]. | ||
const factory EdgeInsetsGeometry.exceptLeft(double value, [double left]) = EdgeInsets.exceptLeft; | ||
/// Creates insets where all sides are [value] except [right]. | ||
const factory EdgeInsetsGeometry.exceptRight(double value, [double right]) = | ||
EdgeInsets.exceptRight; | ||
/// An [EdgeInsets] with zero offsets in each direction. | ||
static const EdgeInsetsGeometry zero = EdgeInsets.zero; | ||
@@ -431,6 +461,74 @@ class EdgeInsets extends EdgeInsetsGeometry { | ||
right = horizontal, | ||
bottom = vertical; | ||
/// Creates insets where all sides are [value], except the excluded ones. | ||
/// | ||
///{@tool snippet} | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// const EdgeInsets.some(rest: 8.0, top: true); // -> left: 8, right: 8, bottom: 8, top: 0 | ||
/// ``` | ||
/// {@end-tool} | ||
Mohamed-7018 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const EdgeInsets.some({ | ||
double rest = 0.0, | ||
double? left, | ||
double? top, | ||
double? right, | ||
double? bottom, | ||
}) : left = left ?? rest, | ||
top = top ?? rest, | ||
right = right ?? rest, | ||
bottom = bottom ?? rest; | ||
/// Creates insets where all sides are set to [value] except the [top], which is | ||
/// `0.0` by default. | ||
/// | ||
/// {@tool snippet} | ||
/// ```dart | ||
/// // Creates insets: left=16, right=16, bottom=16, top=0 | ||
/// const EdgeInsets.exceptTop(16.0); | ||
/// ``` | ||
/// {@end-tool} | ||
const EdgeInsets.exceptTop(double value, [double top = 0.0]) | ||
: this.only(left: value, top: top, right: value, bottom: value); | ||
/// Creates insets where all sides are set to [value] except the [bottom], which is | ||
/// `0.0` by default. | ||
/// | ||
/// {@tool snippet} | ||
/// ```dart | ||
/// // Creates insets: left=12, right=12, top=12, bottom=0 | ||
/// const EdgeInsets.exceptBottom(12.0); | ||
/// ``` | ||
/// {@end-tool} | ||
const EdgeInsets.exceptBottom(double value, [double bottom = 0.0]) | ||
: this.only(left: value, top: value, right: value, bottom: bottom); | ||
/// Creates insets where all sides are set to [value] except the [left], which is | ||
/// `0.0` by default. | ||
/// | ||
/// {@tool snippet} | ||
/// ```dart | ||
/// // Creates insets: top=20, right=20, bottom=20, left=0 | ||
/// const EdgeInsets.exceptLeft(20.0); | ||
/// ``` | ||
/// {@end-tool} | ||
const EdgeInsets.exceptLeft(double value, [double left = 0.0]) | ||
: this.only(left: left, top: value, right: value, bottom: value); | ||
/// Creates insets where all sides are set to [value] except the [right], which is | ||
/// `0.0` by default. | ||
/// | ||
/// {@tool snippet} | ||
/// ```dart | ||
/// // Creates insets: top=8, left=8, bottom=8, right=0 | ||
/// const EdgeInsets.exceptRight(8.0); | ||
/// ``` | ||
/// {@end-tool} | ||
const EdgeInsets.exceptRight(double value, [double right = 0.0]) | ||
: this.only(left: value, top: value, right: right, bottom: value); | ||
/// Creates insets that match the given view padding. | ||
/// | ||
/// If you need the current system padding or view insets in the context of a | ||
@@ -760,6 +858,57 @@ class EdgeInsetsDirectional extends EdgeInsetsGeometry { | ||
this.bottom = 0.0, | ||
}); | ||
/// Creates [EdgeInsetsDirectional] where all sides default to [rest], | ||
/// but allows overriding individual sides. | ||
/// | ||
/// This is similar to [EdgeInsets.all], but with optional overrides. | ||
/// | ||
/// For example: | ||
/// ```dart | ||
/// EdgeInsetsDirectional.some(rest : 20, top: 0, start: 8); | ||
Mohamed-7018 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
/// // -> start=8, top=0, end=20, bottom=20 | ||
/// ``` | ||
const EdgeInsetsDirectional.some({ | ||
double rest = 0.0, | ||
double? start, | ||
double? top, | ||
double? end, | ||
double? bottom, | ||
}) : this.only( | ||
start: start ?? rest, | ||
top: top ?? rest, | ||
end: end ?? rest, | ||
bottom: bottom ?? rest, | ||
); | ||
/// Creates [EdgeInsetsDirectional] where all sides are [value], | ||
/// except [start] which defaults to `0.0`. | ||
/// | ||
/// This is useful when you want equal padding on all sides except | ||
/// the `start` side in an LTR/RTL-aware layout. | ||
/// | ||
/// For example: | ||
/// ```dart | ||
/// EdgeInsetsDirectional.exceptStart(16); | ||
/// // -> start=0, top=16, end=16, bottom=16 | ||
/// ``` | ||
const EdgeInsetsDirectional.exceptStart(double value, [double start = 0.0]) | ||
: this.only(start: start, top: value, end: value, bottom: value); | ||
/// Creates [EdgeInsetsDirectional] where all sides are [value], | ||
/// except [end] which defaults to `0.0`. | ||
/// | ||
/// This is useful when you want equal padding on all sides except | ||
/// the `end` side in an LTR/RTL-aware layout. | ||
/// | ||
/// For example: | ||
/// ```dart | ||
/// EdgeInsetsDirectional.exceptEnd(16); | ||
/// // -> start=16, top=16, end=0, bottom=16 | ||
/// ``` | ||
const EdgeInsetsDirectional.exceptEnd(double value, [double end = 0.0]) | ||
: this.only(start: value, top: value, end: end, bottom: value); | ||
/// Creates insets with symmetric vertical and horizontal offsets. | ||
/// | ||
/// This is equivalent to [EdgeInsets.symmetric], since the inset is the same | ||
125 changes: 125 additions & 0 deletionspackages/flutter/test/painting/edge_insets_test.dart
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.