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

150 lines
4.1 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({
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,
this.formatInputs,
this.enabled = true,
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;
final List<TextInputFormatter>? formatInputs;
final bool enabled;
2022-11-29 13:16:44 +01:00
@override
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,
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,
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,
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,
}) : 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;
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;
@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,
2022-11-29 13:16:44 +01:00
),
),
],
);
}
}