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

[Bug] getLeft and getRight return wrong result when in middle with a little offset #206

Closed
SteveCruise opened this issue Mar 25, 2022 · 7 comments · Fixed by #264
Closed
Assignees
Labels
bug Something isn't working

Comments

@SteveCruise
Copy link

Describe the bug
getLeft and getRight return wrong result when in middle with a little offset.

Expected behavior
Text in one line.

Screenshots
image

Desktop (please complete the following information):

  • OS: windows
@SteveCruise
Copy link
Author

_getRight() is wrong!

double? _getRight() {
    if (_isRight()) {
      var rightPadding =
          widget.position!.getCenter() + (_getTooltipWidth() / 2);
      if (rightPadding + _getTooltipWidth() > widget.screenSize!.width) {
        rightPadding = 14;
      }
      return rightPadding;
    } else if (!(_isLeft())) {
      return widget.position!.getCenter() - (_getTooltipWidth() * 0.5);
    } else {
      return null;
    }
  }

should be

  double? _getRight() {
    if (_isRight()) {
      var rightPadding =
          widget.position!.getCenter() + (_getTooltipWidth() / 2);
      if (rightPadding + _getTooltipWidth() > widget.screenSize!.width) {
        rightPadding = 14;
      }
      return rightPadding;
    } else if (!(_isLeft())) {
      return widget.screenSize!.width - widget.position!.getCenter() - (_getTooltipWidth() * 0.5);
    } else {
      return null;
    }
  }

The result
image

@SteveCruise
Copy link
Author

Please fix this

@SteveCruise
Copy link
Author

Why use _getTooltipWidth() caculate so many times? The code is so ineffective.

@bismarabia
Copy link

@simform-solutions I can confirm this issue, as well as the solution provided by @SteveCruise

Thanks for the fix @SteveCruise you should make PR and submit it...

@DhavalRKansara
Copy link
Collaborator

@SteveCruise @bismarabia Thanks for reporting the issue and providing a solution as well, But from our end, I am not able to replicate this issue with our example. Can you please share some code snippets in which you are facing the same issue, So we can work on it?

@DhavalRKansara
Copy link
Collaborator

@SteveCruise @bismarabia Do you guys have any update regarding the same? Are you guys still facing this issue with the latest release of the package?

@KoheiKanagu
Copy link

@DhavalRKansara
An example that can reproduce the problem is described below.
This problem occurs in showcaseview: ^1.1.8.

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

class Demo extends StatelessWidget {
  const Demo({
    super.key,
  });

  static const showcaseKey = GlobalObjectKey('value');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ShowCaseWidget(
          builder: Builder(
            builder: (context) {
              return Row(
                children: [
                  SizedBox(
                    width: MediaQuery.of(context).size.width / 2,
                  ),
                  Showcase(
                    key: showcaseKey,
                    description: 'Why not in one line?',
                    child: ElevatedButton(
                      child: const Text('Tips'),
                      onPressed: () {
                        ShowCaseWidget.of(context).startShowCase([
                          showcaseKey,
                        ]);
                      },
                    ),
                  ),
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}

@vatsaltanna vatsaltanna added the bug Something isn't working label Aug 20, 2022
@vatsaltanna vatsaltanna self-assigned this Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants