Skip to content

Instantly share code, notes, and snippets.

@esarbanis
Last active June 29, 2023 05:57
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save esarbanis/7052b3d69c6113afe7925d3e285a15c0 to your computer and use it in GitHub Desktop.
Save esarbanis/7052b3d69c6113afe7925d3e285a15c0 to your computer and use it in GitHub Desktop.
//This file is in `./lib` folder
import 'package:http/http.dart' show Client;
import '.env.dart';
class Repository {
final String _baseUrl = environment.baseUrl;
Client _client;
DebtorRepository() {
this._client = Client();
}
// For simplicity's sake we will not deal with json encoding/decoding
Future<any> info(String token) async {
return await this._client.get('$_baseUrl/info');
}
}
#!/bin/bash
dart tool/env.dart
//This file is in `./tool` folder
import 'dart:convert';
import 'dart:io';
Future<void> main() async {
final config = {
'baseUrl': Platform.environment['APP_BASE_URL'],
'credentials': Platform.environment['APP_CREDENTIALS'],
};
final filename = 'lib/.env.dart';
File(filename).writeAsString('final environment = ${json.encode(config)};');
}
@nimi0112
Copy link

nimi0112 commented Jan 8, 2021

Hi @esarbanis do you have any sample project for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment