'Flutter storing a widget in Provider class and reusing it in multiple widgets

Hey Stack overflow community please go easy on me if this question is not a good one :)

Is there any advantage to initialising a widget such as SizedBox with a fixed height within a Provider class that I will use in all my widgets to create a padding within columns.

My thoughts were that because I initialise it once it will be more efficient than to keep creating the same widget over and over again inside all other widgets within my widget tree.

My intuition is that instead of recreating the stateless widget each time, it will reference that same SizedBox that I defined initially in my provider. Also this will make it easier to have the same padding across all of my pages.

For example in C you can either allocate new memory for a new object or store the pointer to that object and just use that pointer to get the object like that. Obviously I might be completely wrong and hence my question.

Thanks in advance :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source