Flutter - Push and Get value between routes

前端 未结 5 2070
终归单人心
终归单人心 2021-02-04 02:25

How do I send the green string from the HomePage page to the ContaPage page?

I think it\'s so Navigator.of(context).pushNamed(\'/conta/green\'); but I do no

5条回答
  •  星月不相逢
    2021-02-04 02:47

    It is a bit late, but it might help some one. I think the best way is to use flutter route project fluro.

    define some where globally:

    final router = Router();
    

    after that define the routes

    var contaHandler = Handler(handlerFunc: (BuildContext context, Map params) {
      return ContaPage(color: params["color"][0]);
    });
    
    void defineRoutes(Router router) {
      router.define("/conta/:color", handler: contaHandler);
    }
    

    set the onGenerateRoute in MaterialApp to use the router generator:

     new MaterialApp (
       ...
       nGenerateRoute: router.generator
       ...
     ),
    

    you have to add the fluro in the dependencies :

     dependencies:
         fluro: "^1.3.4"
    

    and do the package upgrade by the following or the IDE way.

     flutter packages upgrade
    

提交回复
热议问题