bensonarafat / super_tooltip

SuperTooltip It is super flexible and allows you to display ToolTips in the overlay of the screen.
https://pub.dev/packages/super_tooltip
MIT License
141 stars 95 forks source link

Passed decoration shape is ignored #67

Closed silverhairs closed 1 year ago

silverhairs commented 1 year ago

Currently the SuperTooltip class takes a decoration field just like a Tooltip class but the shape field inside that decoration is completely ignored. I would suggest either to hide it or to use it to override the default shape cause it's a bit confusing, for example I spent the last 2hours thinking that there was an issue with my custom painter just to realize that it was being completely ignored by the SuperTooltip class.

Code snippet to reproduce

class CustomTooltip extends StatefulWidget {
  const CustomTooltip({required this.child, super.key});

  final Widget child;

  @override
State<CustomTooltip> createState() => _CustomTolltipState();
}

class _CustomTolltipState extends State<CustomTooltip> {
  final _controller = SuperTooltipController();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      Future.delayed(const Duration(seconds: 1), _controller.showTooltip);
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return SuperTooltip(
      showBarrier: false,
      borderRadius: 8,
      bottom: 5,
      hasShadow: false,
      popupDirection: TooltipDirection.up,
      borderColor: Colors.teal[700]!,
      showCloseButton: ShowCloseButton.none,
      backgroundColor: Colors.teal[700],
      content: ConstrainedBox(
        constraints: const BoxConstraints(maxWidth: Spacing.s52),
        child: Row(
          children: [
            Expanded(
              child: Text(
                'Example',
                style: context.textTheme.labelLarge?.copyWith(
                  color: Colors.white,
                ),
              ),
            ),
            SizedBox.square(
              dimension: Spacing.s8,
              child: IconButton(
                iconSize: Spacing.s4,
                onPressed: () {},
                icon: const Icon(
                  Icons.close,
                  color: Colors.white,
                ),
              ),
            )
          ],
        ),
      ),
      controller: _controller,
      decoration: const ShapeDecoration(
        shape: CustomShape(),
      ),
      child: widget.child,
    );
  }
}

class CustomShape extends ShapeBorder {
  const CustomShape();

  @override
  EdgeInsetsGeometry get dimensions =>
      const EdgeInsets.only(bottom: Spacing.s10);

  @override
  Path getInnerPath(Rect rect, {TextDirection? textDirection}) => Path();

  @override
  Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
    return Path()
      ..addRRect(
        RRect.fromRectAndRadius(rect, const Radius.circular(8)),
      )
      ..moveTo(rect.bottomCenter.dx - 15, rect.bottomCenter.dy)
      ..relativeArcToPoint(
        Offset(rect.bottomCenter.dx - 4, rect.bottomCenter.dy),
        radius: const Radius.circular(100),
      )
      // ..moveTo(rect.bottomCenter.dx, rect.bottomCenter.dy)
      ..relativeLineTo(10, 20)
      ..relativeArcToPoint(
        Offset(rect.bottomCenter.dx - 4, rect.bottomCenter.dy),
        radius: const Radius.circular(100),
      )
      ..relativeLineTo(10, -20)
      ..close();
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}

  @override
  ShapeBorder scale(double t) => this;
}
Flutter Doctor ``` [!] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-arm64, locale en-DE) • Flutter version 3.10.6 on channel stable at /Users/silverhairs/fvm/versions/3.10.6 ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.0/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/silverhairs/fvm/versions/3.10.6. Consider adding /Users/silverhairs/fvm/versions/3.10.6/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (6 weeks ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at /Users/silverhairs/Library/Android/sdk • Platform android-33, build-tools 33.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.12.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) [✓] VS Code (version 1.81.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.70.0 [✓] Connected device (4 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • iPhone (mobile) • 00008101-00120D212EFA001E • ios • iOS 16.6 20G75 • macOS (desktop) • macos • darwin-arm64 • macOS 13.4.1 22F770820d darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.96 ! Error: iPhone is busy: Making iPhone ready for development. Xcode will continue when iPhone is finished. (code -10) [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
bensonarafat commented 1 year ago

@silverhairs Thanks for this. I'll work on it