coingaming / moon_flutter

Moon Design System for Flutter
https://flutter.moon.io
MIT License
125 stars 14 forks source link

Tooltip appearance issue #391

Closed Djsmk123 closed 3 months ago

Djsmk123 commented 3 months ago

facing an issue related to tooltip appearance, Tooltip does not appear until hot reload or setState called.

import 'package:moon_design/moon_design.dart';

class Tooltip extends StatefulWidget {
  const Tooltip({super.key});

  @override
  State<Tooltip> createState() => _TooltipState();
}

class _TooltipState extends State<Tooltip> {
  bool showOnTap = true;

  @override
  Widget build(BuildContext context) {
    return MoonTooltip(
      show: showOnTap,
      content: const Text('This is MoonTooltip'),
      child: Text('This is tooltip')
    );
  }
}

I further explore and found out showTooltip method is not being called in initstate but yes it is being called on didupdatewidget. That's why on hot-reload and setState tooltip is being shown.

Purposed solution:

  void initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((Duration _) {
      widget.routeObserver
          ?.subscribe(this, ModalRoute.of(context)! as PageRoute<dynamic>);
      // Show the tooltip if it should be shown.
      if (widget.show) {
        _showTooltip();
      }
    });
  }
Kypsis commented 3 months ago

Good catch!

Fixed in 0.52.3 and published to pub.dev