How to define base URL for flutter app in build.gradle file of android?

741
import 'package:flutter/foundation.dart';

if (kReleaseMode) {
  Global.baseurl = "release";
} else if (kProfileMode) {
  Global.baseurl = "profile";
} else {
  Global.baseurl = "debug";
}

this worked for me

Share:
741
Dhruv garg
Author by

Dhruv garg

I have experience with android, flutter, and backend development in node.js and java. Primarily doing backend development nowadays in node.js and some flutter.

Updated on December 24, 2022

Comments

  • Dhruv garg
    Dhruv garg over 1 year

    I am using the dart-define parameter for switching b/w URLs depending upon release or debug build in the flutter app. Now I want to integrate FastLane for CI/CD and don't know how I can use --dart-define parameter from FastLane, as I will have to use Gradle build command from FastLane.

    One possible solution is to use,

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

    as told here https://stackoverflow.com/a/52820431/9917400

    But, I don't want to use this as it can only differentiate b/w prod and dev. If in the future we use a staging server, we will have to again do changes.