1

I'm currently working on a mobile app and i'm implementing a little user first use tutorial.

thus using the showcaseview 2.0.0+1 flutter package.

this package requires to call a callback when a widget is mounted and built.

@override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback(
      (_) => ShowCaseWidget.of(context)
          .startShowCase([_one, _two, _three, _four, _five]),
    );
  }

the only solution being to use stateful widgets.

my issue is that i used a lot of MVVM, change notifiers patterns to avoid using stateful widget in my app. and most of my widget are stateless.

is it really bad, performance wise, if i convert the widgets i want to showcase to stateful ? ( particularly that i won't use setState in those?)

Thank you for your help,

Badr Erraji
  • 141
  • 1
  • 11
  • 1
    I highly doubt that you'll see any noticeable decrease in performance, but if you really want to be sure, you can profile the app's performance with and without using stateful widgets: https://docs.flutter.dev/perf/ui-performance – Michael Horn Dec 28 '22 at 00:55

1 Answers1

0

In terms of performance, there is generally no significant difference in speed between a StatelessWidget and a StatefulWidget if you're not using setState. Since a StatelessWidget doesn't have mutable state, Flutter doesn't need to perform any state-related operations, such as diffing and updating the widget tree when the state changes.

However, it's worth noting that using a StatefulWidget comes with a small overhead due to the associated state object. Even if you don't use setState, the framework still needs to create and manage an instance of State for the widget. This overhead is typically negligible, and unless you have specific requirements that necessitate using a StatefulWidget, you can generally stick with a StatelessWidget for better code simplicity and maintainability.

In terms of quality, both StatelessWidget and StatefulWidget are equally capable of producing high-quality UIs. The choice between them depends on whether you need to manage mutable state within your widget or not. If your UI requires state management, such as responding to user interactions or fetching data asynchronously, then a StatefulWidget is the appropriate choice. However, if your UI is purely based on input props and doesn't require mutable state, a StatelessWidget is sufficient and often recommended for its simplicity and predictability.