build method
Implementation
@override
Widget build(BuildContext context) {
// Check if widget is visible before wasting resources on building it
if (!widget.model.visible) return const Offstage();
// set the border color arrays
// set the border colors
Color? enabledBorderColor =
widget.model.borderColor ?? Theme.of(context).colorScheme.outline;
Color? disabledBorderColor = Theme.of(context).disabledColor;
Color? focusBorderColor = Theme.of(context).focusColor;
Color? errorBorderColor = Theme.of(context).colorScheme.error;
// set the text color arrays
Color? enabledTextColor = widget.model.textcolor;
Color? disabledTextColor = Theme.of(context).disabledColor;
Color? errorTextColor = Theme.of(context).colorScheme.error;
double? fontsize = widget.model.size;
String? hint = widget.model.hint;
// Check if widget is visible before wasting resources on building it
if (!widget.model.visible) return const Offstage();
String? value = widget.model.value;
cont = TextEditingController(text: value);
double pad = 4;
// View
Widget view;
view = GestureDetector(
//a wee bit janky way of copying and highlighting entire selection without datepicker opening.
onLongPress: () {
focusNode!.requestFocus();
cont!.selection =
TextSelection(baseOffset: 0, extentOffset: cont!.value.text.length);
Clipboard.setData(ClipboardData(text: cont!.text));
},
onTap: () async {
focusNode!.requestFocus();
if (widget.model.editable) {
widget.model.isPicking = true;
await show();
widget.model.isPicking = false;
}
},
child: view = Container(
color: Colors.transparent,
child: IgnorePointer(
child: TextField(
keyboardType: TextInputType.none,
showCursor: false,
focusNode: focusNode,
onChanged: (val) => onChange(val),
controller: cont,
autofocus: false,
enabled: widget.model.enabled,
style: TextStyle(
color: widget.model.enabled
? enabledTextColor ??
Theme.of(context).colorScheme.onBackground
: disabledTextColor,
fontSize: fontsize),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
isDense: false,
errorMaxLines: 8,
hintMaxLines: 8,
fillColor: widget.model.getFieldColor(context),
filled: true,
contentPadding: EdgeInsets.only(
left: pad + 10,
top: pad + 15,
right: pad + 10,
bottom: pad + 15),
alignLabelWithHint: true,
labelStyle: TextStyle(
fontSize: fontsize != null ? fontsize - 2 : 14,
color: widget.model.getErrorHintColor(context),
),
counterText: "",
errorText: widget.model.alarm,
errorStyle: TextStyle(
fontSize: fontsize ?? 12,
fontWeight: FontWeight.w300,
color: errorTextColor,
),
hintText: hint,
hintStyle: TextStyle(
fontSize: fontsize ?? 14,
fontWeight: FontWeight.w300,
color: widget.model.getErrorHintColor(context),
),
prefixIcon: Padding(
padding:
const EdgeInsets.only(right: 10, left: 10, bottom: 0),
child: Icon(widget.model.icon ??
(widget.model.type.toLowerCase() == "time"
? Icons.access_time
: Icons.calendar_today))),
prefixIconConstraints: const BoxConstraints(maxHeight: 24),
suffixIcon: null,
suffixIconConstraints: null,
border: _getBorder(enabledBorderColor, null),
errorBorder: _getBorder(errorBorderColor, null),
focusedErrorBorder: _getBorder(focusBorderColor, null),
focusedBorder: _getBorder(focusBorderColor, null),
enabledBorder: _getBorder(enabledBorderColor, null),
disabledBorder:
_getBorder(disabledBorderColor, enabledBorderColor),
),
),
),
),
);
if (widget.model.dense) {
view = Padding(padding: const EdgeInsets.all(4), child: view);
}
// get the model constraints
var modelConstraints = widget.model.constraints;
// constrain the input to 200 pixels if not constrained by the model
if (!modelConstraints.hasHorizontalExpansionConstraints) {
modelConstraints.width = 200;
}
// add margins
view = addMargins(view);
// apply user defined constraints
view = applyConstraints(view, widget.model.constraints);
// apply visual transforms
view = applyTransforms(view);
return view;
}