Skip to content

Commit 43dc3fc

Browse files
authored
Added EdgeInsetsDirectional.copyWith (#137559)
Added `EdgeInsetsDirectional.copyWith` named constructor. Fixes #137475
1 parent b1f5d96 commit 43dc3fc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/flutter/lib/src/painting/edge_insets.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,22 @@ class EdgeInsetsDirectional extends EdgeInsetsGeometry {
904904
return EdgeInsets.fromLTRB(start, top, end, bottom);
905905
}
906906
}
907+
908+
/// Creates a copy of this EdgeInsetsDirectional but with the given
909+
/// fields replaced with the new values.
910+
EdgeInsetsDirectional copyWith({
911+
double? start,
912+
double? top,
913+
double? end,
914+
double? bottom,
915+
}) {
916+
return EdgeInsetsDirectional.only(
917+
start: start ?? this.start,
918+
top: top ?? this.top,
919+
end: end ?? this.end,
920+
bottom: bottom ?? this.bottom,
921+
);
922+
}
907923
}
908924

909925
class _MixedEdgeInsets extends EdgeInsetsGeometry {

packages/flutter/test/painting/edge_insets_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,10 @@ void main() {
279279
expect(const EdgeInsetsDirectional.only(top: 4.0).add(const EdgeInsets.only(right: 3.0)).toString(), 'EdgeInsets(0.0, 4.0, 3.0, 0.0)');
280280
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)');
281281
});
282+
283+
test('EdgeInsetsDirectional copyWith', () {
284+
const EdgeInsetsDirectional sourceEdgeInsets = EdgeInsetsDirectional.only(start: 1.0, top: 2.0, bottom: 3.0, end: 4.0);
285+
final EdgeInsetsDirectional copy = sourceEdgeInsets.copyWith(start: 5.0, top: 6.0);
286+
expect(copy, const EdgeInsetsDirectional.only(start: 5.0, top: 6.0, bottom: 3.0, end: 4.0));
287+
});
282288
}

0 commit comments

Comments
 (0)