2022-11-29 13:16:44 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2023-12-07 14:29:38 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2022-11-29 13:16:44 +01:00
|
|
|
|
2023-03-26 12:16:25 +02:00
|
|
|
class FlutterFormInputPlainText extends StatelessWidget {
|
2022-11-29 13:16:44 +01:00
|
|
|
const FlutterFormInputPlainText({
|
|
|
|
Key? key,
|
|
|
|
this.label,
|
2023-01-11 10:28:25 +01:00
|
|
|
this.focusNode,
|
2022-11-29 13:16:44 +01:00
|
|
|
this.decoration,
|
|
|
|
this.textAlignVertical,
|
|
|
|
this.expands = false,
|
|
|
|
this.maxLines = 1,
|
|
|
|
this.scrollPadding,
|
|
|
|
this.maxLength,
|
|
|
|
this.keyboardType,
|
|
|
|
this.initialValue,
|
|
|
|
this.onChanged,
|
|
|
|
this.onSaved,
|
|
|
|
this.validator,
|
|
|
|
this.onFieldSubmitted,
|
2022-12-01 11:08:06 +01:00
|
|
|
this.style,
|
2023-12-07 14:29:38 +01:00
|
|
|
this.formatInputs,
|
2023-10-26 14:08:21 +02:00
|
|
|
this.enabled = true,
|
2023-12-14 16:24:51 +01:00
|
|
|
this.textCapitalization = TextCapitalization.none,
|
2024-01-23 13:11:28 +01:00
|
|
|
this.obscureText = false,
|
2022-11-29 13:16:44 +01:00
|
|
|
}) : super(
|
|
|
|
key: key,
|
|
|
|
);
|
|
|
|
|
|
|
|
final InputDecoration? decoration;
|
|
|
|
final TextAlignVertical? textAlignVertical;
|
|
|
|
final bool expands;
|
|
|
|
final int? maxLines;
|
|
|
|
final int? maxLength;
|
|
|
|
final EdgeInsets? scrollPadding;
|
|
|
|
final TextInputType? keyboardType;
|
|
|
|
final Widget? label;
|
2023-01-11 10:28:25 +01:00
|
|
|
final FocusNode? focusNode;
|
2022-11-29 13:16:44 +01:00
|
|
|
final String? initialValue;
|
|
|
|
final Function(String?)? onSaved;
|
2022-11-29 13:37:58 +01:00
|
|
|
final String? Function(String?)? validator;
|
2022-11-29 13:16:44 +01:00
|
|
|
final Function(String?)? onChanged;
|
|
|
|
final Function(String?)? onFieldSubmitted;
|
2022-12-01 11:08:06 +01:00
|
|
|
final TextStyle? style;
|
2023-12-07 14:29:38 +01:00
|
|
|
final List<TextInputFormatter>? formatInputs;
|
2023-10-26 14:08:21 +02:00
|
|
|
final bool enabled;
|
2023-12-14 16:24:51 +01:00
|
|
|
final TextCapitalization textCapitalization;
|
2024-01-23 13:11:28 +01:00
|
|
|
final bool obscureText;
|
2022-11-29 13:16:44 +01:00
|
|
|
|
|
|
|
@override
|
2023-03-26 12:16:25 +02:00
|
|
|
Widget build(BuildContext context) {
|
2022-11-29 13:16:44 +01:00
|
|
|
InputDecoration inputDecoration = decoration ??
|
|
|
|
InputDecoration(
|
|
|
|
label: label ?? const Text("Plain text"),
|
|
|
|
);
|
|
|
|
|
|
|
|
return TextFormField(
|
2022-12-01 11:08:06 +01:00
|
|
|
style: style,
|
2023-12-07 14:29:38 +01:00
|
|
|
inputFormatters: formatInputs,
|
2022-11-29 13:16:44 +01:00
|
|
|
scrollPadding: scrollPadding ?? const EdgeInsets.all(20.0),
|
|
|
|
initialValue: initialValue,
|
2023-01-11 10:28:25 +01:00
|
|
|
focusNode: focusNode,
|
2022-11-29 13:16:44 +01:00
|
|
|
onSaved: (value) => onSaved?.call(value),
|
|
|
|
validator: (value) => validator?.call(value),
|
|
|
|
onChanged: (value) => onChanged?.call(value),
|
|
|
|
onFieldSubmitted: (value) => onFieldSubmitted?.call(value),
|
|
|
|
decoration: inputDecoration,
|
|
|
|
textAlignVertical: textAlignVertical,
|
|
|
|
expands: expands,
|
|
|
|
maxLines: maxLines,
|
|
|
|
maxLength: maxLength,
|
|
|
|
keyboardType: keyboardType,
|
2023-10-26 14:08:21 +02:00
|
|
|
enabled: enabled,
|
2023-12-14 16:24:51 +01:00
|
|
|
textCapitalization: textCapitalization,
|
2024-01-23 13:11:28 +01:00
|
|
|
obscureText: obscureText,
|
2022-11-29 13:16:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FlutterFormInputMultiLine extends StatelessWidget {
|
|
|
|
const FlutterFormInputMultiLine({
|
|
|
|
Key? key,
|
|
|
|
this.label,
|
2023-01-11 10:28:25 +01:00
|
|
|
this.focusNode,
|
2022-11-29 13:16:44 +01:00
|
|
|
this.hint,
|
|
|
|
this.maxCharacters,
|
2023-10-26 14:08:21 +02:00
|
|
|
this.enabled = true,
|
2022-11-29 13:16:44 +01:00
|
|
|
this.scrollPadding,
|
|
|
|
this.keyboardType,
|
|
|
|
this.initialValue,
|
|
|
|
this.decoration,
|
|
|
|
this.onChanged,
|
|
|
|
this.onSaved,
|
|
|
|
this.validator,
|
|
|
|
this.onFieldSubmitted,
|
2023-12-14 16:24:51 +01:00
|
|
|
this.textCapitalization = TextCapitalization.sentences,
|
2022-11-29 13:16:44 +01:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final Widget? label;
|
2023-01-11 10:28:25 +01:00
|
|
|
final FocusNode? focusNode;
|
2022-11-29 13:16:44 +01:00
|
|
|
final String? hint;
|
|
|
|
final int? maxCharacters;
|
2023-10-26 14:08:21 +02:00
|
|
|
final bool enabled;
|
2022-11-29 13:16:44 +01:00
|
|
|
|
|
|
|
final InputDecoration? decoration;
|
|
|
|
final EdgeInsets? scrollPadding;
|
|
|
|
final TextInputType? keyboardType;
|
|
|
|
final String? initialValue;
|
|
|
|
final Function(String?)? onSaved;
|
2022-11-29 13:37:58 +01:00
|
|
|
final String? Function(String?)? validator;
|
2022-11-29 13:16:44 +01:00
|
|
|
final Function(String?)? onChanged;
|
|
|
|
final Function(String?)? onFieldSubmitted;
|
2023-12-14 16:24:51 +01:00
|
|
|
final TextCapitalization textCapitalization;
|
2022-11-29 13:16:44 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: FlutterFormInputPlainText(
|
|
|
|
label: label,
|
|
|
|
textAlignVertical: TextAlignVertical.top,
|
|
|
|
expands: true,
|
|
|
|
maxLines: null,
|
2023-01-11 10:28:25 +01:00
|
|
|
focusNode: focusNode,
|
2022-11-29 13:16:44 +01:00
|
|
|
maxLength: maxCharacters,
|
|
|
|
initialValue: initialValue,
|
|
|
|
scrollPadding: scrollPadding,
|
|
|
|
keyboardType: keyboardType,
|
|
|
|
onSaved: onSaved,
|
|
|
|
validator: validator,
|
|
|
|
onChanged: onChanged,
|
|
|
|
onFieldSubmitted: onFieldSubmitted,
|
|
|
|
decoration: decoration ??
|
|
|
|
InputDecoration(
|
|
|
|
hintText: hint,
|
|
|
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
isDense: true,
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Color(0xFF979797)),
|
|
|
|
),
|
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Color(0xFF979797)),
|
|
|
|
),
|
|
|
|
filled: true,
|
|
|
|
),
|
2023-10-26 14:18:51 +02:00
|
|
|
enabled: enabled,
|
2023-12-14 16:24:51 +01:00
|
|
|
textCapitalization: textCapitalization,
|
2022-11-29 13:16:44 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|