letsar / flutter_sticky_header

Flutter implementation of sticky headers for sliver
MIT License
903 stars 171 forks source link

localPosition in GestureDetector details is incorrect #64

Open natalieeeflores opened 3 years ago

natalieeeflores commented 3 years ago

The vertical offset of the localPosition for onTapDown, when a GestureDetector is used in the child sliver, is offset by the size of the header in the sticky header component. For example, I would expect the top right corner of the container to be (0, 0) but if the header is 40 pixels high the top right corner is actually (0, 40).

Here's a gif, illustrating the issue: Kapture 2021-05-18 at 18 21 27

Here is a minimal reproduction case:

import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('EXAMPLE'),
        ),
        body: CustomScrollView(
          slivers: [
            StickyHeaderExample(),
          ],
        ),
      ),
    ),
  );
}

class StickyHeaderExample extends StatefulWidget {
  @override
  _StickyHeaderExampleState createState() => _StickyHeaderExampleState();
}

class _StickyHeaderExampleState extends State<StickyHeaderExample> {
  Offset tapPosition;
  @override
  Widget build(BuildContext context) {
    return SliverStickyHeader(
      header: SizedBox(
        height: 40,
        child: Center(child: Text('Header')),
      ),
      sliver: SliverList(
        delegate: SliverChildListDelegate(
          [
            Padding(
              padding: const EdgeInsets.only(bottom: 10),
              child: GestureDetector(
                onTapDown: (details) {
                  setState(() {
                    tapPosition = details.localPosition;
                  });
                },
                child: Container(
                  height: 200,
                  color: Colors.lightBlue,
                  alignment: Alignment.center,
                  child: tapPosition != null
                      ? Text(
                          'dy: ${tapPosition.dy}',
                          style: TextStyle(color: Colors.white),
                        )
                      : null,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
letsar commented 2 years ago

What is the version you use? Is it the same with the latest one?