Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Flutter capable of dynamically loading and building widgets during runtime?

Is there any by which I can store multiple dart files on some server and retrieve any one of those file during run-time in such a way that Flutter is able to build a particular widget from the file it receives?

like image 551
Son of Stackoverflow Avatar asked Sep 19 '25 15:09

Son of Stackoverflow


2 Answers

You cannot dynamically load dart files or create new classes, no.

On the other hand, the widget tree is created at runtime, and widgets are composable by nature. So it is totally possible to make a function that deserialize some data into a widget tree.

We could, for example, write a widget tree as an xml/yaml/whatever like so:

type: Row
children:
  - type: Container
    color: red
    child:
      - type: Text
        0: hello world

And have a function deserialize it into:

Row(
  children: [
    Container(
      color: Colors.red,
      child: Text('hello world'),
    ),
  ],
),
like image 116
Rémi Rousselet Avatar answered Sep 21 '25 05:09

Rémi Rousselet


Remote flutter widgets - A mechanism for rendering widgets based on declarative UI descriptions that can be obtained at runtime.

like image 34
selvan Avatar answered Sep 21 '25 06:09

selvan