SimformSolutionsPvtLtd / flutter_showcaseview

Flutter plugin that allows you to showcase your features on flutter application. 👌🔝🎉
https://pub.dev/packages/showcaseview
MIT License
1.48k stars 433 forks source link

Showcase.withWidget: Incorrect Tooltip Positioning #432

Closed himanshu-newstok closed 2 months ago

himanshu-newstok commented 4 months ago

Describe the bug When using Showcase.withWidget, the positioning of the tooltip is incorrect.

To Reproduce Steps to reproduce the behavior:

  1. Add the minimal code

    
    class MyHomePage extends StatefulWidget {
    const MyHomePage({super.key});
    
    @override
    State<MyHomePage> createState() => _MyHomePageState();
    }

class _MyHomePageState extends State { GlobalKey<State> keyBtn = GlobalKey(); late BuildContext ctx; bool setContext = true;

@override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback( (_) => ShowCaseWidget.of(ctx).startShowCase([ keyBtn, ]), ); }

Widget customToolTip( {required GlobalKey<State> key, required String title, required Widget child}) { return Showcase.withWidget( key: key, height: 300, width: 200, container: Text( title, style: const TextStyle(color: Colors.white), ), child: child); }

@override Widget build(BuildContext cx) { return ShowCaseWidget( builder: Builder( builder: (context) { if (setContext) { setContext = false; ctx = context; } return Scaffold( body: SizedBox( width: double.infinity, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ customToolTip( key: keyBtn, title: 'click here', child: Container( color: Colors.orange, child: const Text('Language')), ), ], ), ), ); }, ), ); } }


2. Run the code.

**Expected behavior**
The tooltip needs to be centered, similar to how it appears when using Showcase, but it is not currently positioned correctly.

**Screenshots**
When using ShowCase.withWidget:
![image](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/assets/165873189/ee264503-1c2e-49f3-bc72-481effe7b64d)

When using ShowCase:
![image](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/assets/165873189/e1c9add5-ca6f-4280-9778-91a733b9f3d2)

**Desktop (please complete the following information):**
 - OS: Windows
 - Browser chrome
 - Version 11

**Smartphone (please complete the following information):**
 - Device: Redmi Note 9
 - OS: Android
 - Browser chrome
 - Version 11

**Additional context**
The position of the tooltip varies depending on the width in Showcase.withWidget, and even when setting the width to 0, it remains improperly positioned. Given this behavior, I aim to avoid relying on static sizing for positioning to ensure responsiveness.
Linkadi98 commented 4 months ago

line 509 in tooltip_widget.dart, the Positioned widget is missing the right property which causes the container (your custom tooltip widget) will be placed at top left. I don't know why the author did this but you need to add value for the right property, just like this:

Positioned( left: _getSpace(), top: contentY - (10 * contentOffsetMultiplier), right: _getSpace(), Your custom tooltip will be placed center.

rashi-simform commented 2 months ago

Hello @Linkadi98 , size provided by you to the Showcase.withWidget, inside your customToolTip Widget, is bigger than the actual size of the tooltip. To solve this issue you can follow either of the two ways: 1) You can use key to get proper values of height and width and use those values. 2) If you want to use any static size then give same size to the text widget as well and you can align the text widget, refer the below code to understand more:

 Widget customToolTip(
      {required GlobalKey<State<StatefulWidget>> key,
      required String title,
      required Widget child}) {
    return Showcase.withWidget(
      key: key,
      height: 300,
      width: 200,
      container: SizedBox(
        width: 200,
        child: Align(
          child: Text(
            title,
            style: const TextStyle(
              color: Colors.white,
            ),
          ),
        ),
      ),
      child: child,
    );
  } 

Please let me know if you need any further help with this.