Skip to content
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

localPosition in GestureDetector details is incorrect #64

Open
natalieeeflores opened this issue May 19, 2021 · 1 comment
Open

localPosition in GestureDetector details is incorrect #64

natalieeeflores opened this issue May 19, 2021 · 1 comment

Comments

@natalieeeflores
Copy link

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
Copy link
Owner

letsar commented Jul 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants