flutter_input_library/lib/src/inputs/text/plain_text.dart

155 lines
4.5 KiB
Dart
Raw Normal View History

2022-11-29 13:16:44 +01:00
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2022-11-29 13:16:44 +01:00
class FlutterFormInputPlainText extends StatelessWidget {
2022-11-29 13:16:44 +01:00
const FlutterFormInputPlainText({
2024-02-02 11:48:45 +01:00
super.key,
2022-11-29 13:16:44 +01:00
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,
this.formatInputs,
this.enabled = true,
this.textCapitalization = TextCapitalization.none,
this.obscureText = false,
2024-02-02 11:48:45 +01:00
});
2022-11-29 13:16:44 +01:00
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;
final List<TextInputFormatter>? formatInputs;
final bool enabled;
final TextCapitalization textCapitalization;
final bool obscureText;
2022-11-29 13:16:44 +01:00
@override
Widget build(BuildContext context) {
2024-02-02 11:48:45 +01:00
var inputDecoration = decoration ??
2022-11-29 13:16:44 +01:00
InputDecoration(
2024-02-02 11:48:45 +01:00
label: label ?? const Text('Plain text'),
2022-11-29 13:16:44 +01:00
);
return TextFormField(
2022-12-01 11:08:06 +01:00
style: style,
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,
enabled: enabled,
textCapitalization: textCapitalization,
obscureText: obscureText,
2022-11-29 13:16:44 +01:00
);
}
}
class FlutterFormInputMultiLine extends StatelessWidget {
const FlutterFormInputMultiLine({
2024-02-02 11:48:45 +01:00
super.key,
2022-11-29 13:16:44 +01:00
this.label,
2023-01-11 10:28:25 +01:00
this.focusNode,
2022-11-29 13:16:44 +01:00
this.hint,
this.maxCharacters,
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,
this.textCapitalization = TextCapitalization.sentences,
2024-02-02 11:48:45 +01:00
});
2022-11-29 13:16:44 +01:00
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;
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;
final TextCapitalization textCapitalization;
2022-11-29 13:16:44 +01:00
@override
2024-02-02 11:48:45 +01:00
Widget build(BuildContext context) => Column(
children: [
Expanded(
child: FlutterFormInputPlainText(
label: label,
textAlignVertical: TextAlignVertical.top,
expands: true,
maxLines: null,
focusNode: focusNode,
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,
2022-11-29 13:16:44 +01:00
),
2024-02-02 11:48:45 +01:00
enabled: enabled,
textCapitalization: textCapitalization,
),
2022-11-29 13:16:44 +01:00
),
2024-02-02 11:48:45 +01:00
],
);
2022-11-29 13:16:44 +01:00
}