yubioath-flutter/lib/widgets/app_input_decoration.dart

103 lines
2.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2024-03-08 11:30:47 +03:00
import 'package:material_symbols_icons/symbols.dart';
class AppInputDecoration extends InputDecoration {
final List<Widget>? suffixIcons;
const AppInputDecoration({
// allow multiple suffixIcons
this.suffixIcons,
// forward other TextField parameters
super.icon,
super.iconColor,
super.label,
super.labelText,
super.labelStyle,
super.floatingLabelStyle,
super.helperText,
super.helperStyle,
super.helperMaxLines,
super.hintText,
super.hintStyle,
super.hintTextDirection,
super.hintMaxLines,
super.hintFadeDuration,
super.error,
super.errorText,
super.errorStyle,
super.errorMaxLines,
super.floatingLabelBehavior,
super.floatingLabelAlignment,
super.isCollapsed,
super.isDense,
super.contentPadding,
super.prefixIcon,
super.prefixIconConstraints,
super.prefix,
super.prefixText,
super.prefixStyle,
super.prefixIconColor,
super.suffixIcon,
super.suffix,
super.suffixText,
super.suffixStyle,
super.suffixIconColor,
super.suffixIconConstraints,
super.counter,
super.counterText,
super.counterStyle,
super.filled,
super.fillColor,
super.focusColor,
super.hoverColor,
super.errorBorder,
super.focusedBorder,
super.focusedErrorBorder,
super.disabledBorder,
super.enabledBorder,
super.border,
super.enabled = true,
super.semanticCounterText,
super.alignLabelWithHint,
super.constraints,
}) : assert(!(suffixIcon != null && suffixIcons != null),
'Declaring both suffixIcon and suffixIcons is not supported.');
@override
Widget? get suffixIcon {
2023-12-15 15:03:54 +03:00
final icons = [
if (super.suffixIcon != null) super.suffixIcon!,
if (suffixIcons != null) ...suffixIcons!,
2024-03-08 11:30:47 +03:00
if (errorText != null) const Icon(Symbols.error),
2023-12-15 15:03:54 +03:00
];
2023-12-15 15:03:54 +03:00
return switch (icons.length) {
0 => null,
1 => icons.single,
_ => Builder(
builder: (context) {
// Apply the constraints to *each* icon.
final constraints = suffixIconConstraints ??
Theme.of(context).visualDensity.effectiveConstraints(
const BoxConstraints(
minWidth: kMinInteractiveDimension,
minHeight: kMinInteractiveDimension,
),
);
return Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
runAlignment: WrapAlignment.center,
children: [
for (Widget icon in icons)
ConstrainedBox(
constraints: constraints,
child: icon,
)
],
);
},
),
};
}
}