Skip to content

Commit

Permalink
Add textFieldDecoration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecatoncheir committed May 30, 2022
1 parent 257a1ae commit a1b29d6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
25 changes: 25 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,31 @@ class _MyHomePageState extends State<MyHomePage> {
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(right: 12),
child: const Text(
"Search:",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: GroupsField(
isScrollable: false,
textFieldDecoration: InputDecoration(
hintText: 'Some hint?',
),
groups: [
simpleGroup,
tagsGroup,
],
),
),
],
),
],
),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/groups_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class GroupsField extends StatefulWidget {
final LogicalKeyboardKey keyForTriggerRemoveField;
final Function? onSubmitted;

final InputDecoration? textFieldDecoration;

const GroupsField({
required this.groups,
super.key,
Expand All @@ -68,6 +70,7 @@ class GroupsField extends StatefulWidget {
this.onSomeFieldOfGroupSelected,
this.keyForTriggerRemoveField = LogicalKeyboardKey.backspace,
this.onSubmitted,
this.textFieldDecoration,
});

@override
Expand Down Expand Up @@ -364,6 +367,7 @@ class _GroupsFieldState extends State<GroupsField> {
lastFieldSize: lastFieldSize,
onSubmitted: widget.onSubmitted,
textFieldFocusNode: _textFieldFocusNode,
inputDecoration: widget.textFieldDecoration,
)
: textFieldBuilder(
context,
Expand Down
21 changes: 14 additions & 7 deletions lib/ui/default_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,37 @@ class DefaultTextField extends StatelessWidget {
final FocusNode? textFieldFocusNode;
final TextEditingController? controller;

final InputDecoration? inputDecoration;

const DefaultTextField({
super.key,
required this.lastFieldSize,
required this.cursorPosition,
this.onSubmitted,
this.textFieldFocusNode,
this.controller,
this.inputDecoration,
});

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

final contentPadding = EdgeInsets.only(
top: cursorPosition.dy,
left: cursorPosition.dx,
bottom: cursorPosition.dy == 0 ? 0 : lastFieldSize.height / 2,
);

final decorator = inputDecoration;

return TextField(
focusNode: textFieldFocusNode,
onSubmitted: (_) => callback == null ? null : callback(),
controller: controller,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
top: cursorPosition.dy,
left: cursorPosition.dx,
bottom: cursorPosition.dy == 0 ? 0 : lastFieldSize.height / 2,
),
),
decoration: decorator == null
? InputDecoration(contentPadding: contentPadding)
: decorator.copyWith(contentPadding: contentPadding, isDense: false),
);
}
}

0 comments on commit a1b29d6

Please sign in to comment.