I’d recommend keeping functions outside the build method. It keeps your code cleaner and avoids recreating the function every time the widget rebuilds, which is better for performance. If it’s a simple one-liner, defining it inside is fine, but for anything more, it's best to separate the logic.
using outside:
- Better for performance in cases where the widget is rebuilt
frequently. This approach is recommended when the function contains
more complex logic, is used in multiple places, or needs to access
class-level state.
using inside:
- For very simple, one-off functions, defining them inside the build
method can be convenient.
- Keeps everything in one place, which might
be preferable for very small widgets.