import 'package:flutter/widgets.dart'; /// Content that scrolls behind a floating top bar, with optional [notices] /// (a connection banner, a refused refresh) that stay put above it. /// /// Without notices [child] reaches the top edge and keeps the bar's height as /// its [MediaQuery.paddingOf] top, so its list starts below the bar at rest /// and scrolls behind it. With notices they sit below the bar and [child] /// below them, no longer seeing the bar's height. [child] keeps its place in /// the tree either way, so a banner coming or going never remounts it. class TopBarNotices extends StatelessWidget { const TopBarNotices({ super.key, this.notices = const [], required this.child, }); final List notices; final Widget child; @override Widget build(BuildContext context) { final media = MediaQuery.of(context); final inset = media.padding.top; final shown = notices.isNotEmpty; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Padding( padding: EdgeInsets.only(top: shown ? inset : 0), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: notices, ), ), Expanded( child: MediaQuery( data: media.copyWith( padding: media.padding.copyWith(top: shown ? 0 : inset), ), child: child, ), ), ], ); } }