Skip to content

Commit 0d18697

Browse files
committed
Implement proper TextFieldModel minimum size computation.
1 parent 8dd555c commit 0d18697

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

lib/src/api/models/box_constraints.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ class BoxConstraintsModel with EquatableMixin, SerializableMixin {
4949
maxHeight: maxHeight,
5050
);
5151

52+
/// Returns new box constraints that are smaller by the given edge dimensions.
53+
BoxConstraintsModel deflate(EdgeInsetsModel edges) {
54+
final double horizontal = edges.horizontal;
55+
final double vertical = edges.vertical;
56+
final double deflatedMinWidth = max(0.0, minWidth! - horizontal);
57+
final double deflatedMinHeight = max(0.0, minHeight! - vertical);
58+
return BoxConstraintsModel(
59+
minWidth: deflatedMinWidth,
60+
maxWidth: max(deflatedMinWidth, maxWidth! - horizontal),
61+
minHeight: deflatedMinHeight,
62+
maxHeight: max(deflatedMinHeight, maxHeight! - vertical),
63+
);
64+
}
65+
5266
/// Duplicates instance of this class with given [minWidth] value override.
5367
BoxConstraintsModel updateMinWidth(double? value) => BoxConstraintsModel(
5468
minWidth: value,
@@ -87,6 +101,8 @@ class BoxConstraintsModel with EquatableMixin, SerializableMixin {
87101
return BoxConstraintsModel(
88102
maxWidth: maxWidth,
89103
maxHeight: maxHeight,
104+
minWidth: 0,
105+
minHeight: 0,
90106
);
91107
}
92108

lib/src/api/models/input_border.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ enum BorderTypeEnum {
2020
outline,
2121

2222
/// Border under the input field.
23-
underline,
23+
underline;
24+
25+
/// A convenience getter to check if this border type is outline.
26+
bool get isOutline => this == BorderTypeEnum.outline;
27+
28+
/// A convenience getter to check if this border type is underline.
29+
bool get isUnderline => this == BorderTypeEnum.underline;
30+
31+
/// A convenience getter to check if this border type is none.
32+
bool get isNone => this == BorderTypeEnum.none;
2433
}
2534

2635
/// Represents decoration for an input border.
@@ -39,6 +48,15 @@ class InputBorderModel with EquatableMixin, SerializableMixin {
3948
/// [InputDecoration.labelText] width gap.
4049
final double gapPadding;
4150

51+
/// A convenience getter to check if this border is outline.
52+
bool get isOutline => borderType.isOutline;
53+
54+
/// A convenience getter to check if this border is underline.
55+
bool get isUnderline => borderType.isUnderline;
56+
57+
/// A convenience getter to check if this border is none.
58+
bool get isNone => borderType.isNone;
59+
4260
/// Creates an instance of input border model.
4361
const InputBorderModel({
4462
this.borderType = BorderTypeEnum.outline,

lib/src/api/utils.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ abstract class ITextSizeCalculator {
2323
/// The details are dependant on the implementation.
2424
double getHeightForWidth(double width);
2525

26-
/// Returns the width of a defined [TextNode] based on its height.
27-
/// The details are dependant on the implementation.
28-
double getWidthForHeight(double height, double fallbackWidth);
29-
3026
/// Returns The minimum possible width of a defined [TextNode].
3127
/// The details are dependant on the implementation.
3228
double getMinWidth();
@@ -40,17 +36,10 @@ abstract class ITextSizeCalculator {
4036
/// The details are dependant on the implementation.
4137
double getBestTextWidthAtCurrentNodeBox(double internalBoxWidth);
4238

43-
/// Returns The minimum height of a defined [TextNode].
44-
/// The details are dependant on the implementation.
45-
double getMinHeight();
46-
4739
/// Returns The distance to the [baseline] of a defined [TextNode].
4840
/// The details are dependant on the implementation.
4941
double computeDistanceToActualBaseline(CTextBaseline baseline);
5042

51-
/// Returns the line height of a single line of text.
52-
double getLineHeight();
53-
5443
/// Disposes of this calculator.
5544
void dispose();
5645
}

0 commit comments

Comments
 (0)