Skip to content

feat!: migrate to the decoupled material_ui package (fixes #237) - #239

Open
qeepcologne wants to merge 1 commit into
Tkko:masterfrom
qeepcologne:material-ui
Open

feat!: migrate to the decoupled material_ui package (fixes #237)#239
qeepcologne wants to merge 1 commit into
Tkko:masterfrom
qeepcologne:material-ui

Conversation

@qeepcologne

Copy link
Copy Markdown

Fixes #237.

Material was decoupled from the Flutter SDK into the material_ui package. The in-SDK package:flutter/material.dart is frozen to contributions and scheduled for removal, so pinput needs to move for apps that have already migrated.

The bug

_PinputState.build asserts debugCheckHasMaterial(context), which resolves the ancestor with LookupBoundary.findAncestorWidgetOfExactType<Material> — an exact type match. A material_ui app's Scaffold provides material_ui's Material, a different class, so the assert always fails:

No Material widget found.
#2  _PinputState.build (package:pinput/src/pinput_state.dart:289:12)

It throws out of build(), so Flutter substitutes an ErrorWidget and the field never renders. assert is debug-only, so release builds are unaffected — which makes it easy to miss: the screen works in release and red-screens under flutter run.

MaterialUiCompatibilityBridge does not help. It supplies a legacy Theme and Localizations, never a legacy Material ancestor. The workaround in #237 (wrapping each Pinput in old.Material(type: transparency)) works but pushes a legacy import back into apps that just removed theirs.

What changed

Import swap only, no logic touched. The whole library is one import line — 11 of the 13 files under lib/src are part of '../pinput.dart'. Also swapped test/ and example/ so they exercise the real target.

Everything pinput uses exists in material_ui with identical semantics: Theme, ThemeData, Colors, TextField (docs), AdaptiveTextSelectionToolbar, and both debugCheckHasMaterial* helpers. After the swap the asserts resolve against material_ui, so a material_ui Scaffold satisfies them.

Worth noting the two asserts are not equivalent, in case removing them was on the table as an alternative fix: debugCheckHasMaterialLocalizations guards something real, since the default contextMenuBuilder is AdaptiveTextSelectionToolbar.editableText, which reads MaterialLocalizations at runtime for the cut/copy/paste labels. Only debugCheckHasMaterial is decorative — pinput never calls Material.of, draws no ink, and TextSelectionToolbar builds its own Material. Migrating keeps both correct rather than trading one problem for another.

Verification

  • flutter analyze lib/ test/ example/ — no errors or warnings.
  • flutter test — 12/12 pass.
  • Reproduced Crashes on Flutter 3.47.0 #237 against published 6.0.2 in a material_ui app: ErrorWidget: 1, EditableText: 0. With this branch and no workaround wrapper: no exception, EditableText: 1.
  • Integrated into a production material_ui app (~450 Dart files, Flutter 3.47.1): analyze clean, test suite green, release-flavour APK builds.

@JesusHdez960717

Copy link
Copy Markdown

@Tkko please merge this, if we use this package in the current version we can't upgrade flutter sdk to 3.47

@Tkko

Tkko commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Hey guys, please use the workaround mentioned here while I'm investigating if I can somehow fully remove the material dependency

@JesusHdez960717

Copy link
Copy Markdown

Hi @Tkko, thanks for letting us know that you're at least going to look into it; let us know if there's anything we can do on our end.

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.

Crashes on Flutter 3.47.0

3 participants