Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.43 KB | Source Code | 0 0
  1. import 'dart:core';
  2. import 'dart:core';
  3. import 'dart:io';
  4. import 'package:intl/intl.dart';
  5.  
  6. import 'package:flutter/material.dart';
  7. import 'package:arboapp/main.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_secure_storage/flutter_secure_storage.dart';
  10. import 'main.dart';
  11. import 'settings.dart';
  12. import 'package:syncfusion_flutter_charts/charts.dart';
  13. import 'package:syncfusion_flutter_charts/sparkcharts.dart';
  14. import 'inter.dart';
  15.  
  16. void main() {
  17.   runApp(const MaterialApp(
  18.       home: Register(
  19.     title: 'dashboard',
  20.   )));
  21. }
  22.  
  23. class ChartData {
  24.   ChartData(this.time, this.value);
  25.  
  26.   final int time;
  27.   final double? value;
  28. }
  29.  
  30. class Dashboard_stless extends StatelessWidget {
  31.   Dashboard_stless({super.key, required String title});
  32.  
  33.   @override
  34.   Widget build(BuildContext context) {
  35.     return MaterialApp(
  36.       title: 'Flutter Demo',
  37.       theme: ThemeData(
  38.         primarySwatch: Colors.deepOrange,
  39.       ),
  40.       home: const Register(title: 'Flutter Demo Home Page'),
  41.     );
  42.   }
  43. }
  44.  
  45. class Register extends StatefulWidget {
  46.   const Register({Key? key, required String title, required}) : super(key: key);
  47.  
  48.   @override
  49.   State<Register> createState() => _DashboardState();
  50. }
  51.  
  52. class _DashboardState extends State<Register> {
  53.   late List<ChartData> _chartData = [ChartData(0, 0)];
  54.   late List<Widget> walletRows = [];
  55.  
  56.   Future<List<ChartData>> getChartData() async {
  57.     const storage = FlutterSecureStorage();
  58.     String token = await storage.read(key: 'token') as String;
  59.     late final List<ChartData> chartData = [];
  60.     List data = await Inter.getChartData(token);
  61.     int i = 0;
  62.     //data.forEach((key, value) => {print(value),chartData.add(ChartData(key,double.parse(value)))});
  63.     data.forEach((element) {
  64.       if (i % 6 == 0) {
  65.         chartData.add(ChartData(element[0], element[1]));
  66.       }
  67.       i += 1;
  68.     });
  69.     print(chartData[0].value);
  70.     return chartData;
  71.   }
  72.  
  73.  
  74.  
  75.   @override
  76.   initState() {
  77.     loadPageData();
  78.     _pageController = PageController();
  79.  
  80.     super.initState();
  81.   }
  82.  
  83.   Future<void> loadPageData() async {
  84.     this._chartData = await getChartData(); // variable to feed sfcartesianchart
  85.     const storage = FlutterSecureStorage(); // getting token for api call
  86.     String token = await storage.read(key: 'token') as String;
  87.     var wallet = WalletRow();
  88.     wallet.addText(token);
  89.     setState(() {
  90.       walletRows = wallet.getWallet();
  91.     }); //setting state with updated walletrows
  92.   }
  93.  
  94.   @override
  95.   Widget build(BuildContext context) {
  96.     SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  97.       statusBarColor: Colors.redAccent, //or set color with: Color(0xFF0000FF)
  98.     ));
  99.  
  100.     [...]
  101.    
  102.     Column(
  103.                         crossAxisAlignment: CrossAxisAlignment.start,
  104.                         children: [
  105.                           Column(
  106.                               crossAxisAlignment: CrossAxisAlignment.start,
  107.                               children: [
  108.                                 const Text(
  109.                                   textAlign: TextAlign.left,
  110.                                   "Synthetic wallet",
  111.                                   style: TextStyle(
  112.                                       fontWeight: FontWeight.bold,
  113.                                       fontSize: 20,
  114.                                       color:
  115.                                           Color.fromARGB(255, 113, 113, 113)),
  116.                                 ),
  117.                                 Container(margin: EdgeInsets.fromLTRB(0, 10, 20.7, 10),
  118.                                     child:
  119.                                 Column(children: walletRows))
  120.  
  121.                               ])]),
  122.                              
  123.                              
  124.                              
  125.                          [...]
  126.                          
  127.                          
  128.                          
  129.                             Container(
  130.                                 width: 350,
  131.                                 child: SfCartesianChart(
  132.                                     primaryXAxis: DateTimeAxis(
  133.                                         labelAlignment: LabelAlignment.start,
  134.                                         edgeLabelPlacement:
  135.                                             EdgeLabelPlacement.none,
  136.                                         labelStyle: const TextStyle(
  137.                                             fontWeight: FontWeight.bold),
  138.                                         dateFormat: DateFormat.Md(),
  139.                                         interval: 1,
  140.                                         isVisible: true,
  141.                                         labelRotation: 0,
  142.                                         majorGridLines: const MajorGridLines(
  143.                                             color: Color.fromARGB(
  144.                                                 255, 250, 250, 250))),
  145.                                     primaryYAxis: NumericAxis(
  146.                                         edgeLabelPlacement:
  147.                                             EdgeLabelPlacement.hide,
  148.                                         labelPosition:
  149.                                             ChartDataLabelPosition.inside,
  150.                                         majorGridLines: const MajorGridLines(
  151.                                             color: Color.fromARGB(
  152.                                                 255, 250, 250, 250)),
  153.                                         labelStyle: const TextStyle(
  154.                                             fontWeight: FontWeight.bold),
  155.                                         tickPosition: TickPosition.inside),
  156.                                     margin: EdgeInsets.fromLTRB(0, 16, 0, 0),
  157.                                     palette: const [
  158.                                       Color.fromARGB(130, 189, 111, 170)
  159.                                     ],
  160.                                     series: <ChartSeries>[
  161.                                       SplineAreaSeries<ChartData, dynamic>(
  162.                                           splineType: SplineType.cardinal,
  163.                                           cardinalSplineTension: 1,
  164.                                           //width: 2.5,
  165.                                           dataSource: _chartData,
  166.                                           xValueMapper: (ChartData data, _) =>
  167.                                               DateTime
  168.                                                   .fromMillisecondsSinceEpoch(
  169.                                                       data.time),
  170.                                           yValueMapper: (ChartData data, _) =>
  171.                                               data.value),
  172.                                     ],
  173.                                     title: ChartTitle(),
  174.                                     legend: Legend(isVisible: false)))
  175.                                    
  176.                                    
  177.                         [...]
  178.                        
  179.                        
  180.   }
  181. }
  182.  
  183. class WalletRow {
  184.   final List<Widget> l = [];
  185.  
  186.   WalletRow();
  187.   String roundTo2ndDecimal(double value) {
  188.     String inString = value.toStringAsFixed(2);
  189.     return inString;
  190.   }
  191.   Future<void> addText(token) async {
  192.     List partialWalletList;
  193.     partialWalletList = await Inter.getWallet(token);
  194.     partialWalletList.forEach((element) {
  195.       l.add(Row(mainAxisAlignment:
  196.       MainAxisAlignment.spaceBetween,children: [
  197.         Text(element[0]),
  198.         Text(roundTo2ndDecimal(element[1])),
  199.         Text(roundTo2ndDecimal(element[2]))
  200.       ]));
  201.     });
  202.   }
  203.  
  204.   List<Widget> getWallet() {
  205.     return l;
  206.   }
  207. }
  208.  
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement