Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add const to TextInputFormatter #114592

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

Closed

Conversation

shogohida
Copy link
Contributor

@shogohida shogohida commented Nov 3, 2022

Fixes #114401

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Nov 3, 2022
@shogohida
Copy link
Contributor Author

It seems test failures are not related to the change I made so I decided to open this pull request

@shogohida shogohida marked this pull request as ready for review November 3, 2022 10:58
@LongCatIsLooong
Copy link
Contributor

Thanks for contributing. The change makes sense to me, but the test failures are related, "Linux analyze" is complaining there's missing documentation. Also this seems to be testable, could you add a test for that?

@shogohida
Copy link
Contributor Author

@LongCatIsLooong
Thanks for your comment! I have 2 questions.

  1. I couldn't see that "Linux analyze" is complaining there's missing documentation... I saw the error message below but nothing else. Could you show me the specific point where Linux analyze is complaining? I will fix the code according to that point.
For your convenience, the error messages reported above are repeated here:
Command exited with exit code 1 but expected: zero exit code.
Command: bin/flutter analyze --flutter-repo
Relative working directory: .
Command exited with exit code 1 but expected: zero exit code.
Command: bin/flutter analyze --flutter-repo --watch --benchmark
Relative working directory: .
  1. Is there any good example in Flutter code I can refer to in order to write a test? I wasn't sure if I should write a test to examine const constructer can be created in TextInputFormatter class or its sub classes.

Thanks for your support!

@LongCatIsLooong
Copy link
Contributor

You should be able to find plenty of examples here: https://github.com/flutter/flutter/blob/master/packages/flutter/test/services/text_formatter_test.dart.

The test failure is here: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8798526700594975537/+/u/Analyze/analyze/test_stdout. The new public constructor needs to be documented.

@shogohida shogohida marked this pull request as draft November 5, 2022 07:17
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@shogohida
Copy link
Contributor Author

@LongCatIsLooong
I added documentation and tests but it seems tests I added are wrong.... I tried to create tests referring to the file you shared but I don't know yet what kind of tests I should add.

Could you give me a clear code example of tests? It would be so helpful. Thanks in advance.

@@ -7,6 +7,13 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('test const constructor', () {
const testValue1 = TextInputFormatter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextInputFormatter is an abstract class and cannot be instantiated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goderbauer
Thanks for your comment. Should I write tests for const constructors of subclasses instead?

@LongCatIsLooong
Copy link
Contributor

For tests I think the ones you added were fine, just have to make sure you can add const to subclasses. But I don't think it makes sense to add a new const constructor that takes no parameters for every subclass.

@shogohida
Copy link
Contributor Author

shogohida commented Nov 22, 2022

@LongCatIsLooong
Thanks for your comment! Are these changes fine then? I thought this is what you said above

ad66a5d

@@ -7,6 +7,19 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('test const constructor', () {
const testValue1 = _SimpleTextInputFormatter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't have a const constructor or a constructor that takes 0 arguments. Could you create a concrete TextInputFormatter sub-class in the test file, with a const constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for replying late. Is my understanding correct?

8b96bf0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can declare inline classes in dart. You can try out the test by following this section from the wiki

@goderbauer
Copy link
Member

(triage): @shogohida looks like the checks failed due to some infra issue. Could you merge in the latest master to kick the checks again? Thanks.

engine-flutter-autoroll and others added 13 commits December 7, 2022 22:01
* Allows pushing page based route as pageless route

* update
* delete screenshot_test.dart

* remove image dep

* pub get
…lutter#115672)

* a76ec9158 Roll Fuchsia Linux SDK from lnmSnyJi-2H07tBnV... to WdtwlLEce90PjFJ9z... (flutter/engine#37747)

* 44e2f5854 [Impeller] Change texture upload pipeline in Vulkan (flutter/engine#37623)

* 6a3ad3c14 Roll Skia from 345bceacd298 to 5270b1d26b5f (4 revisions) (flutter/engine#37748)

* 01271891c Do not abort if a MultiFrameCodec is unable to allocate a bitmap buffer (flutter/engine#37534)

* 54232a4c3 Roll Skia from 5270b1d26b5f to cf967e6b1c00 (5 revisions) (flutter/engine#37751)

* 30aa3cc38 [fuchsia][a11y] Set explicit hit regions in flatland embedder (flutter/engine#37338)

* da07c33d2 Make NotifyIdle reject close and past deadlines. (flutter/engine#37737)

* e3844cc1e Add third_party/dart/third_party/binaryen/src as a dependency (flutter/engine#37749)

* aeb2cd95b [Impeller] use SSBOs for gradients where supported (metal/vulkan) (flutter/engine#37654)

* e8aa1c192 Roll Skia from cf967e6b1c00 to f1f59de17204 (2 revisions) (flutter/engine#37756)

* 4311774fb [Impeller] register modern shaders on Vulkan too (flutter/engine#37757)

* 8e4a718d0 Made FlutterTextField that outlive FlutterTextPlatformNode not crash (flutter/engine#37735)

* 446a09dfc [macOS] Use consistent filenames for tests (flutter/engine#37755)

* 7a390f97c Roll Skia from f1f59de17204 to 12f01bc5b57e (1 revision) (flutter/engine#37760)
mit-mit and others added 7 commits December 7, 2022 22:02
…lutter#116620)

* 143977b53 Roll Skia from b63a254727f3 to 13e5241ce8b7 (6 revisions) (flutter/engine#38106)

* 9554754ac [web:canvaskit] test zero font size (flutter/engine#37916)

* 4f22c2789 Roll Skia from 13e5241ce8b7 to aea62b0970c3 (2 revisions) (flutter/engine#38107)
* Remove flaky label

* Have test install debug version

* Fix test

* Undo change

* Properly test change

* Empty-Commit

* Revert testing changes
* Add ListenableBuilder with examples

* Add tests

* Add tests

* Fix Test

* Change AnimatedBuilder to be a subclass of ListenableBuilder
* Make some minor changes in preparation for updating the Time Picker to M3

* Revert OutlineInputBorder.borderRadius type change

* Revert more OutlineInputBorder.borderRadius changes.
…lutter#116632)

* 267f0d849 Roll Skia from aea62b0970c3 to dd3285a80b23 (1 revision) (flutter/engine#38111)

* 5ad341776 [Impeller] Remove unused flag enable-impeller-vulkan. (flutter/engine#38109)

* 185e2f3d4 Pin the analyzer package version in lib/web_ui (flutter/engine#38114)
…lutter#116633)

* 5429243d3 [Impeller Scene] Render imported meshes (flutter/engine#38097)

* 67254d6e4 Use announce function in live region (flutter/engine#38084)
@shogohida shogohida changed the base branch from master to 3.3 December 7, 2022 13:04
@shogohida shogohida changed the base branch from 3.3 to master December 7, 2022 13:04
@flutter-dashboard flutter-dashboard bot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: internationalization Supporting other languages or locales. (aka i18n) a: tests "flutter test", flutter_test, or one of our tests d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation engine flutter/engine repository. See also e: labels. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. c: contributor-productivity Team-specific productivity, code health, technical debt. c: tech-debt Technical debt, code quality, testing, etc. tool Affects the "flutter" command-line tool. See also t: labels. platform-ios iOS applications specifically labels Dec 7, 2022
@shogohida
Copy link
Contributor Author

shogohida commented Dec 7, 2022

@goderbauer
Thanks for your comment. I tried to rebase but it seems I made mistakes in the process. I will make a new pull request from the latest master and close this one for a moment.

I'm very sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: internationalization Supporting other languages or locales. (aka i18n) a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. c: tech-debt Technical debt, code quality, testing, etc. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos engine flutter/engine repository. See also e: labels. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add const constructor to TextInputFormatter