I was wondering if it's possible to wrap a widget in the widget tree at runtime with another widget?
An example of this would be you a TextField on screen, when I tap on it I wrap a container around it and re-render the widget tree. This is not for in production use and will only be for debug use so no need to worry about the optimisation of the flutter tree.
Any example of this would be highly appreciated.
Related
I have developed an application in Flutter Dart and used an Expanded widget in my application but wherever I used expanded widget, it destroyed my UI and converted that List into an infinite list with no data on it.
Please let me know that reason why does this occur and the potential solution.
Thank you everyone in advance
You can use the expanded widget inside the column and row. Sometimes with use of an expanded widget with the wrong widget will give the error in release mode while it is working in the debug mode.
Make sure you are using the expanded widget inside the column or row and that column and row should not be inside the scroll view or other scrollable widgets.
If still not clear then update the question with the widget hierarchy.
in VS code
For example, I wrap with widget in flutter's widget.
Next, I try to convert what is written as a widget into a GestureDetector.
When I type 'Ges', the widgets should be recommended with AutoComplete, but it doesn't work.
Please let me know how I can fix this.
I'm quite new to flutter and I'm trying to figure out the best way to build my widgets in the aspect of good performance while I have three choices:
1- Stateful Wigdet.
2- Stateless Widget.
3- Widget function(){} with a StatefulBuilder if needed.
Thanks.
A StatefulWidget has State, which means that you can change stuff inside the widget without needing to destroy it and create a new version. They work slower than StatelessWidget but are better for checkboxes or screens which need to be frequently updated.
A StatelessWidget is locked, and you cannot change values once it is initiated. In order to change things inside the widget, you need to re-call the build function to build an updated version. They are quite fast but are best used for static screens.
Widget function(){} widgets are custom-made. Essentially, you can take any existing widget and modify it, adding childs and other widgets to it. However, the widget type normally inherits from a StatefulWidget or StatelessWidget. These can cover basically everything.
I want to show an floating notification widget on the entire widgets of the application (on the top of MaterialApp widget).
So i find two possible way to do that :
wrap MaterialApp widget with a Stack widget
insert my widget as OverlayEntry (Overlay.of(context).insert(MyNotificationOverlay()))
So i'm confused to choice best option to improve performance of the app for this requirement(showing notificatioin as floating widget entire the app (for example i want to show upload progress with this notification))
Thanks for your help
OverlayEntry creates in top of widgets. but after finish using you will remove it. If you can write your code by Stack use Stack widget.
Overlay is an kind of dynamic stack. Whenever you want to show some widgets at some specific time (like it would be in an stack) we use overlay. Else when we are sure to have some things in form of stack already, we use stack.
The overlayentry use custom stack but the broblem with overlayEntry it rebuild it self when you use some widget outside it like
Pupop menu button and when writing text form feild .
In my project i have different container widgets that are placed one above the another in a stack layout and i have performed set of canvas drawing on each container widget based on my scenario. My question is "how to refresh or call set state for a particular container widget without rendering all the widgets"?.
Thanks in advance,
Ashwin
You will need transform your "Container" in a custom statefull widget and then make his state management by your needs. Take a look at BLoC pattern here. With this pattern you will be able to update a specific widget in all widget tree without recreate all widgets.