Chapter 2 - Function returns a Widget vs Stateless Widget

Is there a reason for building a function to return the Recipe Card (buildRecipeCard) instead of creating a stateless Widget to render the card?

I’m trying to first read the chapter, build it myself, and compare my code to the example to better understand the concept.

Following my flow, I wrote a widget dedicated to render the RecipeCard by passing the required values to the constructor.

Did I get it wrong?

2 Likes

@lanzoninicola definitely a solid approach. Creating a Stateless/ stateful widget is the right way to go especially when you want to reuse the recipe card widget in different places of your app.

If you use a function within a widget, you are restricted to only the boundaries of that widget.

Maybe you could share your code?