Dhruv garg
Dhruv garg

Reputation: 844

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

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.

Upvotes: 4

Views: 1786

Answers (1)

Dhruv garg
Dhruv garg

Reputation: 844

import 'package:flutter/foundation.dart';

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

this worked for me

Upvotes: 3

Related Questions