Created
September 12, 2018 11:30
-
-
Save ahmadmarafa/c4b7afe157b96182831958d4f7180289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async' ; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:http/http.dart' as http; | |
class Api | |
{ | |
SharedPreferences prefs ; | |
String locale = "en" ; | |
Api() { this.init(); } | |
init() async { | |
prefs = await SharedPreferences.getInstance() ; | |
this.locale = prefs.getString("locale") ?? "en"; | |
} | |
Future get(url, {Map<String, String> headers} ) async { | |
var uri = Uri.parse(url); | |
url+= uri.queryParametersAll.length == 0 ? "?locale=${this.locale.toString()}" : "&locale=${this.locale.toString()}"; | |
debugPrint("lisyncLogs ${url}"); | |
try { | |
return await http.get(url , headers: headers) ; | |
} catch(exception) { | |
var completer = new Completer(); | |
completer.completeError('ERROR'); | |
return completer.future; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment