I know we are supposed to use composition over inheritance in Flutter. And that works great when we are talking about Widgets
.
But what am I supposed to do when a class is not a Widget
?
For example, I want my TextFields
in some screens to have a specific set of values in their InputDecoration
.
Should I extend InputDecoration
? How can I reuse this specific InputDecoration
in many TextFields?
EDIT:
Following Rémi Rousselet's guidance, I extended InputDecoration
. Here's the final result:
class LoginInputDecoration extends InputDecoration {
@override
InputBorder get errorBorder =>
UnderlineInputBorder(borderSide: BorderSide(color: AppColors.danger));
@override
EdgeInsetsGeometry get contentPadding => const EdgeInsets.symmetric(
horizontal: Dimens.halfSpace,
vertical: Dimens.singleSpace,
);
@override
InputBorder get border =>
UnderlineInputBorder(borderSide: BorderSide(color: AppColors.primary));
@override
TextStyle get labelStyle =>
TextStyle(color: AppColors.white, decorationColor: AppColors.white);
@override
InputBorder get enabledBorder =>
UnderlineInputBorder(borderSide: BorderSide(color: AppColors.primary));
@override
TextStyle get hintStyle =>
TextStyle(color: AppColors.white, decorationColor: AppColors.white);
LoginInputDecoration({String labelText}) : super(labelText: labelText);
}