candlesticks 2.1.0 candlesticks: ^2.1.0 copied to clipboard
A high-performance full featured candlesticks chart for all platforms.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:candlesticks/candlesticks.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<Candle> candles = [];
bool themeIsDark = false;
@override
void initState() {
fetchCandles().then((value) {
setState(() {
candles = value;
});
});
super.initState();
}
Future<List<Candle>> fetchCandles() async {
final uri = Uri.parse(
"https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1h");
final res = await http.get(uri);
return (jsonDecode(res.body) as List<dynamic>)
.map((e) => Candle.fromJson(e))
.toList()
.reversed
.toList();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: themeIsDark ? ThemeData.dark() : ThemeData.light(),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("BTCUSDT 1H Chart"),
actions: [
IconButton(
onPressed: () {
setState(() {
themeIsDark = !themeIsDark;
});
},
icon: Icon(
themeIsDark
? Icons.wb_sunny_sharp
: Icons.nightlight_round_outlined,
),
)
],
),
body: Center(
child: Candlesticks(
candles: candles,
),
),
),
);
}
}