Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made FormBuilderTextField support context menu by default. #1212

Merged

Conversation

MuhammadNFadhil
Copy link
Contributor

Connection with issue(s)

Close #1204 #1194

Solution description

Quoting from #1194:

Currently, default value for contextMenuBuilder parameter of FormBuilderTextBox is not specified, so no context menu is shown as default.
In contrast, native TextFormField specifies default implementation using AdaptiveTextSelectionToolbar.editableText.
It is great if FormBuilderTextField also support default context menu.

For your reference, the default context menu enables pasting from clipboard, selecting all inputs if there are any inputs, and cutting and copying seleted texts. I think these functions are "must-have" for UX.

Simply, because of that, no context menu was showing for the FormBuilderTextField widget.

Solution

I simply used the same approach used by flutter's TextField widget. I first created a static method that provides us with the default context menu widget:

static Widget _defaultContextMenuBuilder(
  BuildContext context,
  EditableTextState editableTextState,
) {
  return AdaptiveTextSelectionToolbar.editableText(
    editableTextState: editableTextState,
  );
}

And the I used that as a default value for FormBuilderTextField.:

FormBuilderTextField({
  super.key,
  required super.name,
  // ...
  this.contextMenuBuilder = _defaultContextMenuBuilder,
  // ...

To Do

  • Read contributing guide
  • Check the original issue to confirm it is fully satisfied
  • Add solution description to help guide reviewers
  • Add unit test to verify new or fixed behaviour
  • If apply, add documentation to code properties and package readme

@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #1212 (4f08cb2) into main (d8fb588) will decrease coverage by 0.24%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1212      +/-   ##
==========================================
- Coverage   83.99%   83.75%   -0.24%     
==========================================
  Files          19       19              
  Lines         706      708       +2     
==========================================
  Hits          593      593              
- Misses        113      115       +2     
Impacted Files Coverage Δ
lib/src/fields/form_builder_text_field.dart 90.69% <0.00%> (-4.43%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@deandreamatias deandreamatias merged commit 71cf8db into flutter-form-builder-ecosystem:main Apr 6, 2023
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormBuilderTextField: ToolbarOptions is deprecated and shouldn't be used. Use contextMenuBuilder instead
2 participants