Flutter - Use JSON to push material route

Viewed 51

I want to use a JSON file to drive some navigation content. The JSON looks like this

 {
                "title": "foo",
                "isDone": false,
                "daily": "Go To Dashboard",
                "action": "Foo()"
            },
            {
                "title": "bar",
                "isDone": false,
                "daily": "Go to reminders",
                "action": "Bar()"
            },
            {
                "title": "rey",
                "isDone": false,
                "daily": "Open YouTube",
                "action": "Rey()"
            }

Basically, the JSON fills in some button information. The actions are pages and should open from the onPressed for a navigator.

  onPressed: () {
           Navigator.push(
             context,
             MaterialPageRoute(
             builder: (context) => ${onboardingTasks[index].tasks[chkBoxindex].action}));
                                                        },

Any clue how to get this to work? The class is currently a String but it just errors me out and i'm not sure what I do to get past it?

I want it to resolve like this:

           Navigator.push(
             context,
             MaterialPageRoute(
             builder: (context) => Rey())); << (Or Bar(), Or foo())
                                                        },

Any help is appreciated!
0 Answers
Related