4

Is there a diference between a function that returns a widget and the Extract Widget that create a class? in terms of performance, best practices, etc.

At first sight I would prefer the function, because is les bulky, but I want to hear your opinions.

Custom Function

Container box() {
  return Container(
    margin: EdgeInsets.all(15.0),
  );
}

This is produced by using the Extract Widget

class BoxExtracted extends StatelessWidget {
  const BoxExtracted({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(15.0),
    );
  }
}
Constantin Groß
  • 10,442
  • 4
  • 20
  • 47
Tapioca
  • 189
  • 2
  • 6
  • I always start from first method, and then If I found out the similar widget used frequently, and changed to second method, and made It more customizable. By the way, there are many aspects to discuss this issue, It might be good on test If you start on second method. – Tokenyet Oct 01 '19 at 04:57
  • 1
    Possible duplicate of [What is the difference between functions and classes to create widgets?](https://stackoverflow.com/questions/53234825/what-is-the-difference-between-functions-and-classes-to-create-widgets) – ibhavikmakwana Oct 01 '19 at 05:55
  • brother take a look : Rémi talked about here: https://stackoverflow.com/questions/53234825/what-is-the-difference-between-functions-and-classes-to-create-reusable-widgets – Paras Arora Jul 29 '20 at 06:41

0 Answers0