0

I am searching this topic and I must confess, I love the using function widgets for my applications. And in the my flutter experience, I never got any error or any unwanted result with this approach(I mean using function widgets).

But while my search, I couldn't totally understand the reason, why I must use the stateless widgets but not function widgets.

An example; I want to create a page, using scaffold, and appar.

My page must be statefull so I want to use

Scaffold scaffold({String pageTitle, Widget body, Widget floatingActionButton, Widget appBarLeading})=>Scaffold(
    appBar: CustomAppBar(pageTitle: pageTitle, leading: appBarLeading),
    body: body,
    floatingActionButton: floatingActionButton,
    floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    backgroundColor: Colors.blueGrey[50],
  );

this code and, my custom appbar coming from Stateless Widget.

So what happen if I use this structure for the beginning ?

İf I use the setstate, my appbar creating from to beginning or used from widget three ?

I can understand the reasons why must use stateless widget because it has final variables and this way, it is reused in the program behalf but What happen If I use stateless widgets in my function widgets ?

Please help me for understanding this topic.

Thank you very much.

leylekseven
  • 687
  • 7
  • 15
  • 1
    Your question is kind of vague. Maybe this link helps you https://stackoverflow.com/questions/53234825/what-is-the-difference-between-functions-and-classes-to-create-reusable-widgets. Also functional widgets are not bad. Another point, when you call setState, all the widgets in that same context gets rebuild. – Syph Apr 04 '21 at 20:36
  • honestly syph, while ı was searching the my question I read that link and also I read some github issiues but in the end I couldn't understand because all of them not exactly clear. They are saying, if you use like function and some widget tree changes happen, you can get some errors or something like that but while my flutter experience, I did not get any error like the description so, I am continuing with function way. And lastly, thank you for your answer, I saw it new. – leylekseven May 16 '21 at 15:31

0 Answers0