IEX JSON API Integration:
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../models/stocks.dart';
Future<Map<String,dynamic>> getStocksData() async {
const url = 'https://cloud.iexapis.com/stable/stock/market/batch?symbols=aapl,fb&types=quote&token=Hidden';
final response = await http.get(url);
final decodedResponse = json.decode(response.body).keys();
final data = Stocks.fromJson(decodedResponse);
return jsonDecode(response.body).keys();
}
{"AAPL":{"stats":{"week52change":0.108189,"week52high":244.8,"week52low":142,"marketcap":1100781864400,"employees":132000,"day200MovingAvg":196.46,"day50MovingAvg":220.62,"float":4512324403.94,"avg10Volume":23328121.8,"avg30Volume":26924247.43,"ttmEPS":11.8267,"ttmDividendRate":2.96,"companyName":"Apple, Inc.","sharesOutstanding":4519180000,"maxChangePercent":240.1683,"year5ChangePercent":1.315,"year2ChangePercent":0.5505,"year1ChangePercent":0.108189,"ytdChangePercent":0.542427,"month6ChangePercent":0.186574,"month3ChangePercent":0.176601,"month1ChangePercent":0.102022,"day30ChangePercent":0.113509,"day5ChangePercent":0.030329,"nextDividendDate":null,"dividendYield":0.012152065029969619,"nextEarningsDate":"2019-10-30","exDividendDate":"2019-08-09","peRatio":20.75,"beta":1.534551916699308},"quote":{"symbol":"AAPL","companyName":"Apple, Inc.","...
Development Logs:
Launching lib\main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... Running Gradle task 'assembleDebug'... Built build\app\outputs\apk\debug\app-debug.apk. I/OpenGLRenderer( 4854): Initialized EGL, version 1.4 D/OpenGLRenderer( 4854): Swap behavior 1 D/ ( 4854): HostConnection::get() New Host Connection established 0xdc20bf00, tid 4881 D/EGL_emulation( 4854): eglCreateContext: 0xe3d47760: maj 2 min 0 rcv 2 D/EGL_emulation( 4854): eglMakeCurrent: 0xe3d47760: ver 2 0 (tinfo 0xc6b24a30) D/ ( 4854): HostConnection::get() New Host Connection established 0xc6b386c0, tid 4874 D/EGL_emulation( 4854): eglCreateContext: 0xdc27d780: maj 2 min 0 rcv 2 D/EGL_emulation( 4854): eglMakeCurrent: 0xdc27d780: ver 2 0 (tinfo 0xc6b24dc0) Syncing files to device Android SDK built for x86... I/Choreographer( 4854): Skipped 279 frames! The application may be doing too much work on its main thread. D/EGL_emulation( 4854): eglMakeCurrent: 0xe3d47760: ver 2 0 ...
Custom Class Definition:
import 'dart:convert';
Stocks stocksFromJson(String str) => Stocks.fromJson(json.decode(str));
String stocksToJson(Stocks data) => json.encode(data.toJson());
class Stocks {
String symbol;
// Include other attributes similar to the existing ones
Stocks({
this.symbol,
// Add more attribute definitions here
});
factory Stocks.fromJson(Map<String, dynamic> json) => Stocks(
symbol: json["symbol"],
// Define mappings for additional attributes
);
Map<String, dynamic> toJson() => {
"symbol": symbol,
// Include mappings for new attributes
};
}
No errors encountered during execution. https://i.sstatic.net/fwBl0.png
Your feedback and support are highly appreciated!