How do I build different versions of my Flutter app for qa/dev/prod?

后端 未结 9 1627
清歌不尽
清歌不尽 2020-12-01 00:14

I am building a Flutter app, and I have variables with different values for different environments (QA, dev, prod, etc). What\'s a good way to organize my app so I can easil

9条回答
  •  生来不讨喜
    2020-12-01 00:56

    Release and debug mode can now be acquired using

    const bool isProduction = bool.fromEnvironment('dart.vm.product');
    

    Because this is a constant it works with tree-shaking.
    So code like

    if(isProduction) {
      // branch 1
    } else {
      // branch 2
    }
    

    would only include one of these two branches into production code depending on isProduction

提交回复
热议问题