Skip to content

Instantly share code, notes, and snippets.

@ahmadmarafa
Created September 12, 2018 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadmarafa/c4b7afe157b96182831958d4f7180289 to your computer and use it in GitHub Desktop.
Save ahmadmarafa/c4b7afe157b96182831958d4f7180289 to your computer and use it in GitHub Desktop.
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