flutter_api
A REST API Connector, you can connect your Flutter Project to any endpoint easily.
Initialization
The baseUri is required and it's used globally
Api.baseUri = Uri.parse('https://query1.finance.yahoo.com/v8/finance/');
Configuration
Api.baseUriused by all the requests. (required)Api.globalDataPathsets the json path of the response forvalue.data.Api.globalErrorPathsets the json path for determine if an error exists in the response.Api.headerscan add any header required by the api.Api.onErrorit's called when has a error on the response.
Functions usage
Api.set()it's make a call to the Api, this don't returns value.Api.get<T>()returns a value.Api.getList<T>()returns aListvalue.Api.getMap<K,V>()returns aMapvalue.
Example:
Api.get<num>(
'chart/${_currencys[0]}=X?includePrePost=false&interval=1d&corsDomain=finance.yahoo.com&.tsrc=finance',
dataPath: 'chart/result/meta/regularMarketPrice')
.then((value) {
print(_currencys[0] + ': ' + value.data.toString());
});
Builders usage
ApiBuilder<T>returns a value._ApiListBuilder<T>returns aListvalue.ApiMapBuilder<K,V>returns aMapvalue.
Example:
ApiBuilder(
url:
'chart/${_currencys[index]}=X?includePrePost=false&interval=1d&corsDomain=finance.yahoo.com&.tsrc=finance',
dataPath: 'chart/result/meta',
showLoading: false,
builder: (value) {
if (!value.hasData) return Text("No Data");
var title = 'USD - ' + value.data['currency'];
return ListTile(
title: Text(title),
subtitle: Text(
DateTime.fromMillisecondsSinceEpoch(
value.data['regularMarketTime'] * 1000)
.toString() +
' (${value.data['timezone']})',
textScaleFactor: .8,
),
trailing: Text(
value.data['regularMarketPrice'].toString() + ' \$'),
);
},
);