-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrollable.ensureVisible(context) broken due to incorrect childScrollOffset() #59
Labels
Comments
Is it still the case? |
We are facing an issue where the header body items are getting scrolled when expanding the header. Reproducible codeimport 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
import 'package:sliver_tools/sliver_tools.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _showHeaderBody = false;
final _duration = Duration(milliseconds: 200);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("Flutter Sticky Header Issue")),
body: CustomScrollView(
slivers: [
MultiSliver(
pushPinnedChildren: true,
children: [
Builder(
builder: (ctx) => SliverStickyHeader(
header: _buildHeader(ctx, 'Header', _showHeaderBody,
callback: (showHeader) =>
setState(() => _showHeaderBody = showHeader)),
sliver: SliverToBoxAdapter(
child: _buildBody(_showHeaderBody),
),
),
),
Builder(
builder: (ctx) => SliverStickyHeader(
header: _buildHeader(ctx, 'Header 2', true),
sliver: SliverToBoxAdapter(child: _buildBody(true)),
),
),
],
),
],
),
),
);
}
Future<void> _showHeaderOnScreen(BuildContext ctx) async {
await Future.delayed(_duration);
WidgetsBinding.instance.addPostFrameCallback((_) {
Scrollable.ensureVisible(ctx, duration: _duration);
});
}
Widget _buildHeader(
BuildContext ctx,
String header,
bool showHeader, {
void Function(bool)? callback,
}) {
return ListTile(
title: Text(header),
onTap: () async {
final expand = !showHeader;
if (expand) await _showHeaderOnScreen(ctx);
callback?.call(expand);
},
);
}
Widget _buildBody(bool expanded) {
return AnimatedCrossFade(
firstChild: Container(height: 0.0),
secondChild: Column(
children: List.generate(50, (index) => Text(index.toString())),
),
crossFadeState:
expanded ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: _duration,
);
}
}
Video with issue issue.movVideo without issue using version 0.6.3 no.issue.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using
Scrollable.ensureVisible(context)
on a child ofSliverStickyHeader
withoverlapsContent: true
, theScrollable
scrolls to the wrong position.The problem appears to be in
childScrollOffset
(https://github.com/letsar/flutter_sticky_header/blob/master/lib/src/rendering/sliver_sticky_header.dart#L346) which returns_headerExtent
even with overlapping headers. I think that should beheaderLogicalExtent
(=overlapsContent ? 0.0 : _headerExtent
).The text was updated successfully, but these errors were encountered: