Skip to content

Commit

Permalink
feat: inputformatters
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Jul 30, 2024
1 parent 56c4b8d commit 4ffd6b8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/src/components/input_field/impaktfull_input_field.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:impaktfull_ui/impaktfull_ui.dart';

class ImpaktfullInputField extends StatefulWidget {
Expand All @@ -11,6 +12,7 @@ class ImpaktfullInputField extends StatefulWidget {
final TextInputType textInputType;
final TextInputAction textInputAction;
final VoidCallback? onSubmit;
final List<TextInputFormatter> inputFormatters;

const ImpaktfullInputField({
required this.onChanged,
Expand All @@ -23,6 +25,7 @@ class ImpaktfullInputField extends StatefulWidget {
this.textInputType = TextInputType.text,
this.textInputAction = TextInputAction.done,
this.onSubmit,
this.inputFormatters = const [],
super.key,
});

Expand All @@ -33,14 +36,22 @@ class ImpaktfullInputField extends StatefulWidget {
class _ImpaktfullInputFieldState extends State<ImpaktfullInputField> {
TextEditingController? _internalTextEditingController;

TextEditingController get _textEditingController =>
_internalTextEditingController ?? widget.controller!;
TextEditingController get _textEditingController => _internalTextEditingController ?? widget.controller!;

@override
void initState() {
super.initState();
if (widget.controller == null) {
_internalTextEditingController =
TextEditingController(text: widget.value);
_internalTextEditingController = TextEditingController(text: widget.value);
}
}

@override
void didUpdateWidget(covariant ImpaktfullInputField oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.value != oldWidget.value && widget.value != _textEditingController.text) {
_textEditingController.text = widget.value;
setState(() {});
}
}

Expand All @@ -62,8 +73,7 @@ class _ImpaktfullInputFieldState extends State<ImpaktfullInputField> {
Container(
decoration: BoxDecoration(
color: theme.colors.card,
borderRadius:
BorderRadius.circular(theme.dimens.generalBorderRadius),
borderRadius: BorderRadius.circular(theme.dimens.generalBorderRadius),
),
padding: const EdgeInsets.symmetric(
horizontal: 16,
Expand All @@ -77,6 +87,7 @@ class _ImpaktfullInputFieldState extends State<ImpaktfullInputField> {
textInputAction: widget.textInputAction,
onSubmitted: (value) => widget.onSubmit?.call(),
style: theme.textStyles.onCardPrimary.bodyInput,
inputFormatters: widget.inputFormatters,
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(bottom: 4),
border: InputBorder.none,
Expand Down

0 comments on commit 4ffd6b8

Please sign in to comment.