perf: fix scroll lag on profile/contribute, unpin calendar gradient

profile_screen: SingleChildScrollView + Column eagerly built every event
card (all images, shadows, tiles) at once even when off-screen. Replaced
with CustomScrollView + SliverList so only visible tiles are built per
frame. Also switches to BouncingScrollPhysics for natural momentum.

contribute_screen: Each _formCard wrapped in RepaintBoundary so form
cards are isolated render layers — one card's repaint doesn't invalidate
its siblings. Added BouncingScrollPhysics to the form SingleChildScrollView.

calendar_screen: Blue gradient banner was Positioned(top:0) making it
sticky even as the user scrolled. Removed the fixed Positioned layer and
moved the gradient inside the CustomScrollView as the first sliver in a
Stack alongside the calendar card (which keeps its y=110 visual overlap).
Now the entire page — gradient, calendar, events — scrolls as one unit.
This commit is contained in:
2026-03-18 17:16:38 +05:30
parent 0982e4fdee
commit d74e637a59
3 changed files with 118 additions and 41 deletions

View File

@@ -1017,15 +1017,26 @@ class _ProfileScreenState extends State<ProfileScreen>
Widget build(BuildContext context) {
final theme = Theme.of(context);
const double headerHeight = 200.0;
const double cardTopOffset = 130.0; // card starts overlapping into header
const double cardTopOffset = 130.0;
Widget sectionTitle(String text) => Padding(
padding: const EdgeInsets.fromLTRB(18, 16, 18, 12),
child: Text(
text,
style: theme.textTheme.titleMedium
?.copyWith(fontWeight: FontWeight.w600, fontSize: 18),
),
);
return Scaffold(
backgroundColor: theme.scaffoldBackgroundColor,
body: SingleChildScrollView(
child: Column(
children: [
// Header + Profile Card overlap using Stack
Stack(
// CustomScrollView: only visible event cards are built — no full-tree Column renders
body: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
// Header gradient + Profile card overlap (same visual as before)
SliverToBoxAdapter(
child: Stack(
children: [
_buildGradientHeader(context, headerHeight),
Padding(
@@ -1034,13 +1045,74 @@ class _ProfileScreenState extends State<ProfileScreen>
),
],
),
),
// Event sections
_buildEventSections(context),
const SizedBox(height: 32),
// ── Ongoing Events ──
if (_ongoingEvents.isNotEmpty) ...[
SliverToBoxAdapter(child: sectionTitle('Ongoing Events')),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 18),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, i) => _eventListTileFromModel(_ongoingEvents[i]),
childCount: _ongoingEvents.length,
),
),
),
const SliverToBoxAdapter(child: SizedBox(height: 24)),
],
),
// ── Upcoming Events ──
SliverToBoxAdapter(child: sectionTitle('Upcoming Events')),
if (_loadingEvents)
const SliverToBoxAdapter(child: SizedBox.shrink())
else if (_upcomingEvents.isEmpty)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
child: Text('No upcoming events',
style: theme.textTheme.bodyMedium
?.copyWith(color: theme.hintColor)),
),
)
else
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 18),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, i) => _eventListTileFromModel(_upcomingEvents[i]),
childCount: _upcomingEvents.length,
),
),
),
const SliverToBoxAdapter(child: SizedBox(height: 24)),
// ── Past Events ──
SliverToBoxAdapter(child: sectionTitle('Past Events')),
if (_loadingEvents)
const SliverToBoxAdapter(child: SizedBox.shrink())
else if (_pastEvents.isEmpty)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
child: Text('No past events',
style: theme.textTheme.bodyMedium
?.copyWith(color: theme.hintColor)),
),
)
else
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 18),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, i) => _eventListTileFromModel(_pastEvents[i], faded: true),
childCount: _pastEvents.length,
),
),
),
const SliverToBoxAdapter(child: SizedBox(height: 32)),
],
),
);
}