Skip to content

TextPainter.getPositionForOffset returns different values when run on web tests #125582

@Renzo-Olivares

Description

@Renzo-Olivares

Is there an existing issue for this?

Info

When tests are run on the web TextPainter.getPositionForOffset returns different values for the same given Offset when compared to other platforms.

Steps to Reproduce

Placing the following test in test/rendering/paragraph_test.dart fails when run with flutter test test/rendering/paragraph_test.dart --platform=chrome. This test also passes when using --web-renderer=canvaskit but fails with skwasm and html. This test passes on other platforms when run with flutter test test/rendering/paragraph_test.dart.

  Offset textOffsetToPosition(RenderParagraph paragraph, int offset) {
    const Rect caret = Rect.fromLTWH(0.0, 0.0, 2.0, 20.0);
    final Offset localOffset = paragraph.getOffsetForCaret(TextPosition(offset: offset), caret);
    return paragraph.localToGlobal(localOffset);
  }

  test('getWordBoundary control test failing', () {
    final RenderParagraph paragraph = RenderParagraph(
      const TextSpan(text: 'How are you?'),
      textDirection: TextDirection.ltr,
    );
    layout(paragraph);

    final Offset target4 = textOffsetToPosition(paragraph, 4);
    final TextPosition position4 = paragraph.getPositionForOffset(target4);
    expect(position4, TextPosition(offset: 4));
    final TextRange range4 = paragraph.getWordBoundary(position4);
    expect(range4.textInside('How are you?'), equals('are'));
  });

Expected results

Test passes on all platforms.

Actual results

Test fails on web with skwasm and html renderers. Returns TextPosition(4, upstream) and other platforms return TextPosition(4, downstream).

Flutter Doctor output

Doctor output
[!] Flutter (Channel unknown, 3.10.0-15.0.pre.34, on macOS 13.3.1 22E261 darwin-arm64, locale en-US)
    ! Flutter version 3.10.0-15.0.pre.34 on channel unknown at /Users/roliv/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision e1844791cf (25 hours ago), 2023-04-25 12:23:16 -0700
    • Engine revision 40187bb9af
    • Dart version 3.1.0 (build 3.1.0-47.0.dev)
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/roliv/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.77.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.62.0

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 14 Pro Max (mobile)  • E36EA4AD-49FE-4C28-9E6D-DECB4487BD46 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.3.1 22E261 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 112.0.5615.137

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsa: typographyText rendering, possibly libtxte: wasmIssues related to the wasm build of Flutter Web.e: web_htmlHTML rendering backend for Webfound in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: solvedIssue is closed as solvedteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions