admin管理员组

文章数量:1406178

I'm trying to implement a chat UI similar to Instagram's direct messages in Flutter. The specific behavior I'm trying to replicate is how Instagram handles the profile header in chats:

The profile header (with user's avatar, name, activity status, etc.) is part of the scrollable content. When the chat has few or no messages, the header appears at the top of the screen with a natural separation between it and any messages. As more messages are added, the header scrolls up naturally as part of the content (it's not fixed or "sticky"). The header behaves like a regular message in the scroll view but with its own specific position in the scroll timeline.

I've tried several approaches:

Regular ListView with manual bottom padding on the header widget. This becomes error prone, and potentially heavy to compute when UI becomes complex to measure.

CustomScrollView's "SliverAppBar", am not able to let it be sticky in the top and smoothly integrate as part of the scrollable content

--

I am just not getting the exact behavior that Instagram has where the header naturally separates from messages when content is minimal but smoothly integrates into the scrollable content as more messages are added. Has anyone successfully replicated this specific UI pattern in Flutter? What's the proper way to implement this behavior?

I'm trying to implement a chat UI similar to Instagram's direct messages in Flutter. The specific behavior I'm trying to replicate is how Instagram handles the profile header in chats:

The profile header (with user's avatar, name, activity status, etc.) is part of the scrollable content. When the chat has few or no messages, the header appears at the top of the screen with a natural separation between it and any messages. As more messages are added, the header scrolls up naturally as part of the content (it's not fixed or "sticky"). The header behaves like a regular message in the scroll view but with its own specific position in the scroll timeline.

I've tried several approaches:

Regular ListView with manual bottom padding on the header widget. This becomes error prone, and potentially heavy to compute when UI becomes complex to measure.

CustomScrollView's "SliverAppBar", am not able to let it be sticky in the top and smoothly integrate as part of the scrollable content

--

I am just not getting the exact behavior that Instagram has where the header naturally separates from messages when content is minimal but smoothly integrates into the scrollable content as more messages are added. Has anyone successfully replicated this specific UI pattern in Flutter? What's the proper way to implement this behavior?

Share Improve this question edited Mar 24 at 6:43 DarkBee 15.5k8 gold badges72 silver badges117 bronze badges asked Mar 23 at 16:45 Joachim BülowJoachim Bülow 1772 silver badges10 bronze badges 3
  • You want some kind of sliver header like SliverResizingHeader or PinnedHeaderSliver. Does SliverResizingHeader perhaps do what you want? – Wh1t3rabbit Commented Mar 24 at 1:59
  • "I've tried several approaches" - Please edit your question to specifically and clearly define the problem that you are trying to solve. Additional details — including all relevant code, error messages, and debugging logs — will help readers to better understand your problem and what you are asking. – DarkBee Commented Mar 24 at 6:44
  • Not sure what you want from this question. My status is that I am essentially measuring the paint bound position of the message field in a post frame callback using a global key. Then performing manual positioning. This is non trivial still tho, as keyboard animations, other widgets, etc. make it hard to maintain that static position. If you go onto the Messenger app it seems like they are actually doing the same thing, as they are visibly recalculating the offset after opening the keyboard, slowly animating chat context down. Only instagram, afaik, have perfected it... – Joachim Bülow Commented Mar 27 at 10:13
Add a comment  | 

1 Answer 1

Reset to default -3

You can use this package, and even customize it if you need, but I recommend not to modify original code, and keep it updatable:

https://pub.dev/packages/flutter_chat_ui

It has nice UI and mimics Instagram, almost.

本文标签: flutterHow to replicate Instagram39s chat UI with a scrollable profile headerStack Overflow