Skip to content

Commit

Permalink
Add OnChanged callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecatoncheir committed May 30, 2022
1 parent a1b29d6 commit 95da6db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/groups_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'group.dart';
export 'bloc/groups_field_bloc.dart';
export 'group.dart';

typedef OnChanged = Function(String text);

/// GroupsField - widget for build ui of custom groups text
/// by some attributes in one text field.
/// Just build ui of GroupsField widget with GroupsFieldBloc.
Expand Down Expand Up @@ -52,6 +54,7 @@ class GroupsField extends StatefulWidget {

final LogicalKeyboardKey keyForTriggerRemoveField;
final Function? onSubmitted;
final OnChanged? onChanged;

final InputDecoration? textFieldDecoration;

Expand All @@ -70,6 +73,7 @@ class GroupsField extends StatefulWidget {
this.onSomeFieldOfGroupSelected,
this.keyForTriggerRemoveField = LogicalKeyboardKey.backspace,
this.onSubmitted,
this.onChanged,
this.textFieldDecoration,
});

Expand Down Expand Up @@ -366,6 +370,7 @@ class _GroupsFieldState extends State<GroupsField> {
cursorPosition: cursorPosition,
lastFieldSize: lastFieldSize,
onSubmitted: widget.onSubmitted,
onChanged: widget.onChanged,
textFieldFocusNode: _textFieldFocusNode,
inputDecoration: widget.textFieldDecoration,
)
Expand Down
13 changes: 11 additions & 2 deletions lib/ui/default_text_field.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:flutter/material.dart';

typedef OnChange = Function(String text);

/// It's a TextField that has a custom cursor position and a custom bottom padding
class DefaultTextField extends StatelessWidget {
final Size lastFieldSize;
final Offset cursorPosition;

final Function? onSubmitted;
final OnChange? onChanged;

final FocusNode? textFieldFocusNode;
final TextEditingController? controller;

Expand All @@ -16,14 +20,16 @@ class DefaultTextField extends StatelessWidget {
required this.lastFieldSize,
required this.cursorPosition,
this.onSubmitted,
this.onChanged,
this.textFieldFocusNode,
this.controller,
this.inputDecoration,
});

@override
Widget build(BuildContext context) {
final callback = onSubmitted;
final onSubmittedCallback = onSubmitted;
final onChangeCallback = onChanged;

final contentPadding = EdgeInsets.only(
top: cursorPosition.dy,
Expand All @@ -35,7 +41,10 @@ class DefaultTextField extends StatelessWidget {

return TextField(
focusNode: textFieldFocusNode,
onSubmitted: (_) => callback == null ? null : callback(),
onSubmitted: (_) =>
onSubmittedCallback == null ? null : onSubmittedCallback(),
onChanged: (text) =>
onChangeCallback == null ? null : onChangeCallback(text),
controller: controller,
decoration: decorator == null
? InputDecoration(contentPadding: contentPadding)
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: groups_field
description: Group widgets by some attribute.
publish_to: "none"
version: 0.2.1
version: 0.3.1

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down

0 comments on commit 95da6db

Please sign in to comment.