Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:core';
- import 'dart:core';
- import 'dart:io';
- import 'package:intl/intl.dart';
- import 'package:flutter/material.dart';
- import 'package:arboapp/main.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_secure_storage/flutter_secure_storage.dart';
- import 'main.dart';
- import 'settings.dart';
- import 'package:syncfusion_flutter_charts/charts.dart';
- import 'package:syncfusion_flutter_charts/sparkcharts.dart';
- import 'inter.dart';
- void main() {
- runApp(const MaterialApp(
- home: Register(
- title: 'dashboard',
- )));
- }
- class ChartData {
- ChartData(this.time, this.value);
- final int time;
- final double? value;
- }
- class Dashboard_stless extends StatelessWidget {
- Dashboard_stless({super.key, required String title});
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.deepOrange,
- ),
- home: const Register(title: 'Flutter Demo Home Page'),
- );
- }
- }
- class Register extends StatefulWidget {
- const Register({Key? key, required String title, required}) : super(key: key);
- @override
- State<Register> createState() => _DashboardState();
- }
- class _DashboardState extends State<Register> {
- late List<ChartData> _chartData = [ChartData(0, 0)];
- late List<Widget> walletRows = [];
- Future<List<ChartData>> getChartData() async {
- const storage = FlutterSecureStorage();
- String token = await storage.read(key: 'token') as String;
- late final List<ChartData> chartData = [];
- List data = await Inter.getChartData(token);
- int i = 0;
- //data.forEach((key, value) => {print(value),chartData.add(ChartData(key,double.parse(value)))});
- data.forEach((element) {
- if (i % 6 == 0) {
- chartData.add(ChartData(element[0], element[1]));
- }
- i += 1;
- });
- print(chartData[0].value);
- return chartData;
- }
- @override
- initState() {
- loadPageData();
- _pageController = PageController();
- super.initState();
- }
- Future<void> loadPageData() async {
- this._chartData = await getChartData(); // variable to feed sfcartesianchart
- const storage = FlutterSecureStorage(); // getting token for api call
- String token = await storage.read(key: 'token') as String;
- var wallet = WalletRow();
- wallet.addText(token);
- setState(() {
- walletRows = wallet.getWallet();
- }); //setting state with updated walletrows
- }
- @override
- Widget build(BuildContext context) {
- SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
- statusBarColor: Colors.redAccent, //or set color with: Color(0xFF0000FF)
- ));
- [...]
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const Text(
- textAlign: TextAlign.left,
- "Synthetic wallet",
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 20,
- color:
- Color.fromARGB(255, 113, 113, 113)),
- ),
- Container(margin: EdgeInsets.fromLTRB(0, 10, 20.7, 10),
- child:
- Column(children: walletRows))
- ])]),
- [...]
- Container(
- width: 350,
- child: SfCartesianChart(
- primaryXAxis: DateTimeAxis(
- labelAlignment: LabelAlignment.start,
- edgeLabelPlacement:
- EdgeLabelPlacement.none,
- labelStyle: const TextStyle(
- fontWeight: FontWeight.bold),
- dateFormat: DateFormat.Md(),
- interval: 1,
- isVisible: true,
- labelRotation: 0,
- majorGridLines: const MajorGridLines(
- color: Color.fromARGB(
- 255, 250, 250, 250))),
- primaryYAxis: NumericAxis(
- edgeLabelPlacement:
- EdgeLabelPlacement.hide,
- labelPosition:
- ChartDataLabelPosition.inside,
- majorGridLines: const MajorGridLines(
- color: Color.fromARGB(
- 255, 250, 250, 250)),
- labelStyle: const TextStyle(
- fontWeight: FontWeight.bold),
- tickPosition: TickPosition.inside),
- margin: EdgeInsets.fromLTRB(0, 16, 0, 0),
- palette: const [
- Color.fromARGB(130, 189, 111, 170)
- ],
- series: <ChartSeries>[
- SplineAreaSeries<ChartData, dynamic>(
- splineType: SplineType.cardinal,
- cardinalSplineTension: 1,
- //width: 2.5,
- dataSource: _chartData,
- xValueMapper: (ChartData data, _) =>
- DateTime
- .fromMillisecondsSinceEpoch(
- data.time),
- yValueMapper: (ChartData data, _) =>
- data.value),
- ],
- title: ChartTitle(),
- legend: Legend(isVisible: false)))
- [...]
- }
- }
- class WalletRow {
- final List<Widget> l = [];
- WalletRow();
- String roundTo2ndDecimal(double value) {
- String inString = value.toStringAsFixed(2);
- return inString;
- }
- Future<void> addText(token) async {
- List partialWalletList;
- partialWalletList = await Inter.getWallet(token);
- partialWalletList.forEach((element) {
- l.add(Row(mainAxisAlignment:
- MainAxisAlignment.spaceBetween,children: [
- Text(element[0]),
- Text(roundTo2ndDecimal(element[1])),
- Text(roundTo2ndDecimal(element[2]))
- ]));
- });
- }
- List<Widget> getWallet() {
- return l;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement