Skip to content

Commit

Permalink
Added EdgeInsetsDirectional.copyWith (#137559)
Browse files Browse the repository at this point in the history
Added `EdgeInsetsDirectional.copyWith` named constructor.

Fixes #137475
  • Loading branch information
piedcipher authored Nov 1, 2023
1 parent b1f5d96 commit 43dc3fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/flutter/lib/src/painting/edge_insets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,22 @@ class EdgeInsetsDirectional extends EdgeInsetsGeometry {
return EdgeInsets.fromLTRB(start, top, end, bottom);
}
}

/// Creates a copy of this EdgeInsetsDirectional but with the given
/// fields replaced with the new values.
EdgeInsetsDirectional copyWith({
double? start,
double? top,
double? end,
double? bottom,
}) {
return EdgeInsetsDirectional.only(
start: start ?? this.start,
top: top ?? this.top,
end: end ?? this.end,
bottom: bottom ?? this.bottom,
);
}
}

class _MixedEdgeInsets extends EdgeInsetsGeometry {
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/test/painting/edge_insets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,10 @@ void main() {
expect(const EdgeInsetsDirectional.only(top: 4.0).add(const EdgeInsets.only(right: 3.0)).toString(), 'EdgeInsets(0.0, 4.0, 3.0, 0.0)');
expect(const EdgeInsetsDirectional.only(start: 4.0).add(const EdgeInsets.only(left: 3.0)).toString(), 'EdgeInsets(3.0, 0.0, 0.0, 0.0) + EdgeInsetsDirectional(4.0, 0.0, 0.0, 0.0)');
});

test('EdgeInsetsDirectional copyWith', () {
const EdgeInsetsDirectional sourceEdgeInsets = EdgeInsetsDirectional.only(start: 1.0, top: 2.0, bottom: 3.0, end: 4.0);
final EdgeInsetsDirectional copy = sourceEdgeInsets.copyWith(start: 5.0, top: 6.0);
expect(copy, const EdgeInsetsDirectional.only(start: 5.0, top: 6.0, bottom: 3.0, end: 4.0));
});
}

0 comments on commit 43dc3fc

Please sign in to comment.