Ensure padding around suffix icons.

This commit is contained in:
Dain Nilsson 2023-12-15 13:03:54 +01:00
parent b37d19164d
commit d8debd239a
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8

View File

@ -64,28 +64,38 @@ class AppInputDecoration extends InputDecoration {
@override @override
Widget? get suffixIcon { Widget? get suffixIcon {
final hasError = errorText != null; final icons = [
if (super.suffixIcon != null) super.suffixIcon!,
if (suffixIcons != null) ...suffixIcons!,
if (errorText != null) const Icon(Icons.error_outlined),
];
if (hasError || suffixIcons != null) { return switch (icons.length) {
final errorIcon = hasError ? const Icon(Icons.error_outlined) : null; 0 => null,
1 => icons.single,
final existingSuffixIcon = super.suffixIcon; _ => Builder(
builder: (context) {
if (errorIcon != null && // Apply the constraints to *each* icon.
(existingSuffixIcon == null && suffixIcons == null)) { final constraints = suffixIconConstraints ??
return errorIcon; Theme.of(context).visualDensity.effectiveConstraints(
} const BoxConstraints(
return Wrap( minWidth: kMinInteractiveDimension,
crossAxisAlignment: WrapCrossAlignment.center, minHeight: kMinInteractiveDimension,
runAlignment: WrapAlignment.center, ),
children: [ );
if (suffixIcons != null) ...suffixIcons!, return Wrap(
if (existingSuffixIcon != null) existingSuffixIcon, crossAxisAlignment: WrapCrossAlignment.center,
if (errorIcon != null) ...[errorIcon, const SizedBox(width: 8.0)], runAlignment: WrapAlignment.center,
], children: [
); for (Widget icon in icons)
} ConstrainedBox(
constraints: constraints,
return super.suffixIcon; child: icon,
)
],
);
},
),
};
} }
} }