Urgent.News

What's breaking now, across hundreds of outlets.

Tech

The keyboard that vanished when the Flutter chat input expanded

You tap the expand button in a chat composer. The input flashes, grows to a few lines, and then the keyboard disappears. The screen is now a large, mostly empty editor, and the thing you were typing with is gone. On top of that, opening the keyboard in the first place feels heavier than it should — not broken, just a beat behind your thumb. Both symptoms live in the same widget, but they have…

The erratic behavior of a Flutter chat input began when the expand button was tapped. The input expanded into a larger editor, leaving the previously used keyboard behind. The keyboard's disappearance and sluggish response seemed to stem from a single widget, but the issues had different origins. One problem was a mistake in the widget tree, while the other stemmed from a subscription that unintentionally expanded the animation to the entire screen.

This article delves into the causes, solutions, and key principles that ensure a smooth composer experience.

Issue One: Keyboard Dropping on Expand

The composer initially had two layouts: a collapsed floating card and an expanded full-height editor. To switch between these states, the composer swapped the widget returned from its wrapper. This change was not a layout modification but a replacement of the widget type, causing Flutter to unmount the existing subtree and rebuild a new one.

This restructuring process led to the keyboard's disappearance and the editor's flashing appearance. Additionally, the expanded height appeared incorrect due to the keyboard's temporary absence.

The underlying issue was that the TextField, responsible for user input, was discarded when the editor was rebuilt, causing the platform input method to close. This resulted in the keyboard being hidden and the editor's layout being rebuilt from scratch. The first principle to remember is to change siblings instead of the entire element chain.

By keeping the composer content in the same position and altering only the surrounding elements, the backdrop can be managed as a sibling, preserving the content's stability. This approach avoids unnecessary reparenting or replacement of the content.

Issue Two: Sluggish Keyboard Animation

The sluggish keyboard animation was another problem that arose from the same widget replacement issue. The keyboard did not appear abruptly but rather through a gradual animation, causing Flutter to resize the Scaffold body in response to the keyboard's changing height. This issue originated from two subscriptions - one for the LayoutBuilder and another for the MediaQuery.of(context).

Both subscriptions triggered a rebuild of the chat every time the keyboard animation occurred, leading to a frame-by-frame rebuild of the entire message list and composer.

The second principle to keep in mind is that a keyboard animation is a constraint animation, not a full layout rebuild. Instead of relying on LayoutBuilder to handle the entire chat's layout, a small layout-reporting proxy was introduced to report the body height. This proxy was then consumed by the composer, which only required the body height during the expanded state.

By caching the boolean decision to hide the header while the keyboard was up and recomputing it only when necessary, the composer no longer needed to rebuild on every animation frame. This approach ensured a smoother keyboard animation experience without affecting the overall chat layout.

In conclusion, by following these two principles - changing siblings instead of the element chain and treating keyboard animations as constraint animations - developers can ensure a more stable and responsive Flutter composer experience. These fixes address the keyboard dropping and sluggish animation issues, ultimately creating a more enjoyable user experience.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Google's MCP-only rule for Workspace agents starts 1 February. Here's a script that finds the REST calls you'll have to move

If you've built an agent that reads someone's Gmail or Drive, Google changed the ground under it this week. Its Workspace MCP servers went generally available on 24 November, together with a new…

  • Google enforces MCP-only rule for Workspace agents starting February 1, 2027
  • Script provided to find and flag direct Google Workspace REST usage
  • Scanner identifies product names, patterns, and OAuth scopes in code

TypeScript: Do you know the differences between type and interface?

They look almost identical, but there are some important differences. Let's explore when to use each. When defining the shape of an object in TypeScript, we generally have two options: type and…

  • Type and interface both describe object shapes with same properties
  • Interfaces can extend other interfaces, type aliases cannot
  • Interfaces support declaration merging, type aliases do not

Free ASO tools and free trials (2026)

Disclosure: I make Asonix, one of the 14. It took me a day of reading pricing pages, help centers and terms (November 28, 2026) to answer it for 14 App Store keyword tools. Five things stood out. 1.

  • Only three ASO tools offer completely free plans without expiration or card requirement.
  • Free plans typically lack crucial data like keyword popularity and difficulty.
  • Five tools provide 7-day trials requiring payment info, with trial lengths from 10 to 30 days.

More from Saturday, 28 November 2026 →