From a25c157649dec39933105a76492fdbefc22b822a Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 21 Jun 2022 17:25:37 +0300 Subject: [PATCH 1/2] graphics and api are updated --- lib/main.dart | 5 + lib/model/CryptoModel.dart | 209 +++++++++++++++++++++++++++++++++++ lib/pages/details_page..dart | 17 ++- lib/pages/home_page.dart | 163 ++++++++++++++------------- pubspec.lock | 46 ++++---- pubspec.yaml | 3 +- 6 files changed, 344 insertions(+), 99 deletions(-) create mode 100644 lib/model/CryptoModel.dart diff --git a/lib/main.dart b/lib/main.dart index cd53801..51d3179 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,6 +28,11 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { + //nomics api key -> 8a1a91ee8c13a4d67af8cac88ba689a1ac124a96 + //messari api key -> ed37c3d9-43af-4528-85a9-1fe47c237ed6 + + //http model -> https://data.messari.io/api/v2/assets?fields=id,slug,symbol,name,metrics/market_data&limit=500 + @override Widget build(BuildContext context) { return Sizer(builder: (context, orientation, deviceType) { diff --git a/lib/model/CryptoModel.dart b/lib/model/CryptoModel.dart new file mode 100644 index 0000000..75bc39d --- /dev/null +++ b/lib/model/CryptoModel.dart @@ -0,0 +1,209 @@ +class CryptoModel { + var status; + List? data; + + CryptoModel({this.status, this.data}); + + CryptoModel.fromJson(Map json) { + status = + json['status'] != null ? new Status.fromJson(json['status']) : null; + if (json['data'] != null) { + data = []; + json['data'].forEach((v) { + data!.add(new Data.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.status != null) { + data['status'] = this.status!.toJson(); + } + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Status { + var elapsed; + var timestamp; + + Status({this.elapsed, this.timestamp}); + + Status.fromJson(Map json) { + elapsed = json['elapsed']; + timestamp = json['timestamp']; + } + + Map toJson() { + final Map data = new Map(); + data['elapsed'] = this.elapsed; + data['timestamp'] = this.timestamp; + return data; + } +} + +class Data { + var id; + var slug; + var symbol; + var name; + Metrics? metrics; + + Data({this.id, this.slug, this.symbol, this.name, this.metrics}); + + Data.fromJson(Map json) { + id = json['id']; + slug = json['slug']; + symbol = json['symbol']; + name = json['name']; + metrics = + json['metrics'] != null ? new Metrics.fromJson(json['metrics']) : null; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['slug'] = this.slug; + data['symbol'] = this.symbol; + data['name'] = this.name; + if (this.metrics != null) { + data['metrics'] = this.metrics!.toJson(); + } + return data; + } +} + +class Metrics { + MarketData? marketData; + + Metrics({this.marketData}); + + Metrics.fromJson(Map json) { + marketData = json['market_data'] != null + ? new MarketData.fromJson(json['market_data']) + : null; + } + + Map toJson() { + final Map data = new Map(); + if (this.marketData != null) { + data['market_data'] = this.marketData!.toJson(); + } + return data; + } +} + +class MarketData { + var priceUsd; + var priceBtc; + var priceEth; + var volumeLast24Hours; + var realVolumeLast24Hours; + var volumeLast24HoursOverstatementMultiple; + var percentChangeUsdLast1Hour; + var percentChangeBtcLast1Hour; + var percentChangeEthLast1Hour; + var percentChangeUsdLast24Hours; + var percentChangeBtcLast24Hours; + var percentChangeEthLast24Hours; + OhlcvLast1Hour? ohlcvLast1Hour; + OhlcvLast1Hour? ohlcvLast24Hour; + String? lastTradeAt; + + MarketData( + {this.priceUsd, + this.priceBtc, + this.priceEth, + this.volumeLast24Hours, + this.realVolumeLast24Hours, + this.volumeLast24HoursOverstatementMultiple, + this.percentChangeUsdLast1Hour, + this.percentChangeBtcLast1Hour, + this.percentChangeEthLast1Hour, + this.percentChangeUsdLast24Hours, + this.percentChangeBtcLast24Hours, + this.percentChangeEthLast24Hours, + this.ohlcvLast1Hour, + this.ohlcvLast24Hour, + this.lastTradeAt}); + + MarketData.fromJson(Map json) { + priceUsd = json['price_usd']; + priceBtc = json['price_btc']; + priceEth = json['price_eth']; + volumeLast24Hours = json['volume_last_24_hours']; + realVolumeLast24Hours = json['real_volume_last_24_hours']; + volumeLast24HoursOverstatementMultiple = + json['volume_last_24_hours_overstatement_multiple']; + percentChangeUsdLast1Hour = json['percent_change_usd_last_1_hour']; + percentChangeBtcLast1Hour = json['percent_change_btc_last_1_hour']; + percentChangeEthLast1Hour = json['percent_change_eth_last_1_hour']; + percentChangeUsdLast24Hours = json['percent_change_usd_last_24_hours']; + percentChangeBtcLast24Hours = json['percent_change_btc_last_24_hours']; + percentChangeEthLast24Hours = json['percent_change_eth_last_24_hours']; + ohlcvLast1Hour = json['ohlcv_last_1_hour'] != null + ? new OhlcvLast1Hour.fromJson(json['ohlcv_last_1_hour']) + : null; + ohlcvLast24Hour = json['ohlcv_last_24_hour'] != null + ? new OhlcvLast1Hour.fromJson(json['ohlcv_last_24_hour']) + : null; + lastTradeAt = json['last_trade_at']; + } + + Map toJson() { + final Map data = new Map(); + data['price_usd'] = this.priceUsd; + data['price_btc'] = this.priceBtc; + data['price_eth'] = this.priceEth; + data['volume_last_24_hours'] = this.volumeLast24Hours; + data['real_volume_last_24_hours'] = this.realVolumeLast24Hours; + data['volume_last_24_hours_overstatement_multiple'] = + this.volumeLast24HoursOverstatementMultiple; + data['percent_change_usd_last_1_hour'] = this.percentChangeUsdLast1Hour; + data['percent_change_btc_last_1_hour'] = this.percentChangeBtcLast1Hour; + data['percent_change_eth_last_1_hour'] = this.percentChangeEthLast1Hour; + data['percent_change_usd_last_24_hours'] = this.percentChangeUsdLast24Hours; + data['percent_change_btc_last_24_hours'] = this.percentChangeBtcLast24Hours; + data['percent_change_eth_last_24_hours'] = this.percentChangeEthLast24Hours; + if (this.ohlcvLast1Hour != null) { + data['ohlcv_last_1_hour'] = this.ohlcvLast1Hour!.toJson(); + } + if (this.ohlcvLast24Hour != null) { + data['ohlcv_last_24_hour'] = this.ohlcvLast24Hour!.toJson(); + } + data['last_trade_at'] = this.lastTradeAt; + return data; + } +} + +class OhlcvLast1Hour { + var open; + var high; + var low; + var close; + var volume; + + OhlcvLast1Hour({this.open, this.high, this.low, this.close, this.volume}); + + OhlcvLast1Hour.fromJson(Map json) { + open = json['open']; + high = json['high']; + low = json['low']; + close = json['close']; + volume = json['volume']; + } + + Map toJson() { + final Map data = new Map(); + data['open'] = this.open; + data['high'] = this.high; + data['low'] = this.low; + data['close'] = this.close; + data['volume'] = this.volume; + return data; + } +} \ No newline at end of file diff --git a/lib/pages/details_page..dart b/lib/pages/details_page..dart index ef9779e..e5d72f2 100644 --- a/lib/pages/details_page..dart +++ b/lib/pages/details_page..dart @@ -283,6 +283,7 @@ class _DetailsPageState extends State { widget.maxY, widget.profitPercent >= 0, ), + ), ), ), @@ -300,7 +301,20 @@ class _DetailsPageState extends State { itemBuilder: (BuildContext context, int i) { return Obx(() => i == selectedSort.value ? GestureDetector( - onTap: () => selectedSort.value = i, + onTap: () { + setState((){ + + selectedSort.value = i; + + }); + if(i == 0) + { + + } + + + + },// onTap: () => selectedSort.value = i, child: chartSortWidget( sortStrings[i], true, themeData)) : GestureDetector( @@ -382,4 +396,5 @@ class _DetailsPageState extends State { ), ); } + } \ No newline at end of file diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 91f4bc8..ddf87a9 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; + +import 'package:crypto_app_flutter/model/CryptoModel.dart'; import 'package:crypto_font_icons/crypto_font_icons.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; @@ -5,6 +8,7 @@ import 'package:sizer/sizer.dart'; import '../widgets/actions/actions_widget.dart'; import '../widgets/balance_panel/balance_panel.dart'; import '../widgets/chart/chart_home_page.dart'; +import 'package:http/http.dart' as http; class AppScreen extends StatefulWidget { const AppScreen({Key? key}) : super(key: key); @@ -14,12 +18,41 @@ class AppScreen extends StatefulWidget { } class _AppScreenState extends State { + + var last1hour = 0; + var last1day = 1; + var last1week = 2; + var last1month = 3; + var last1year = 4; + bool iconBool = false; IconData iconLight = Icons.wb_sunny; IconData iconDark = Icons.nights_stay; double balance = 66032206.10; double profit = 35.22; double profitPercent = 0.22; + bool loading = true; + var cryptoModel = CryptoModel(); + + @override + void initState() { + // TODO: implement initState + fetchCryptoList(); + + super.initState(); + } + // get request + + Future fetchCryptoList() async { + var url = "https://data.messari.io/api/v2/assets?fields=id,slug,symbol,name,metrics/market_data&limit=500"; + var response = await http.get(Uri.parse(url)); + var decodeResponse =jsonDecode(response.body); + cryptoModel = CryptoModel.fromJson(decodeResponse); + setState(() { + loading = false; + }); + } + @override Widget build(BuildContext context) { @@ -52,82 +85,64 @@ class _AppScreenState extends State { body: SafeArea( child: Padding( padding: EdgeInsets.only(top: 2.h), - child: ListView( - children: [ - balancePanel(balance, profit, profitPercent, themeData), - actionsWidget(themeData), - chartHomePage( - true, - CryptoFontIcons.ETH, - 'Ethereum', - 'ETH', - 'USD', - const [ - FlSpot(0, 2550.18), - FlSpot(1, 2500.34), - FlSpot(2, 2541.34), - FlSpot(3, 2540.59), - FlSpot(4, 2550.60), - FlSpot(5, 2639.80), - FlSpot(6, 2523.71), - ], - themeData, - ), - chartHomePage( - true, - CryptoFontIcons.BTC, - 'Bitcoin', - 'BTC', - 'USD', - const [ - FlSpot(0, 40005.71), - FlSpot(1, 40875.23), - FlSpot(2, 40800.59), - FlSpot(3, 40875.12), - FlSpot(4, 41875.72), - FlSpot(5, 40375.49), - FlSpot(6, 40700.58), - ], - themeData, - ), - chartHomePage( - true, - CryptoFontIcons.DOGE, - 'Dogecoin', - 'DOGE', - 'PLN', - const [ - FlSpot(0, 0.22), - FlSpot(1, 0.24), - FlSpot(2, 0.28), - FlSpot(3, 0.30), - FlSpot(4, 0.35), - FlSpot(5, 0.52), - FlSpot(6, 0.58), - ], - themeData, - ), - chartHomePage( - true, - CryptoFontIcons.LTC, - 'Litecoin', - 'LTC', - 'USD', - const [ - FlSpot(0, 100.40), - FlSpot(1, 102.34), - FlSpot(2, 98.23), - FlSpot(3, 100.23), - FlSpot(4, 102.10), - FlSpot(5, 103.85), - FlSpot(6, 103.20), - ], - themeData, - ), - ], - ), + child: SingleChildScrollView( + child: Column( + children: [ + balancePanel(balance, profit, profitPercent, themeData), + actionsWidget(themeData), + Container( + color: Colors.transparent, + height: MediaQuery.of(context).size.height * 0.55, + width: MediaQuery.of(context).size.width, + child: cryptoListView(themeData), + ) + ], + ), + ) ), ), ); } + + Widget cryptoListView(var themeData) + { + if (cryptoModel.data != null) + { + return loading + ? Center(child: CircularProgressIndicator()) + : Column( + children: [ + Container( + child: Expanded( + child: ListView.builder( + + itemCount: cryptoModel.data?.length, + itemBuilder: (context,index){ + return chartHomePage( + true, + CryptoFontIcons.ETH, + cryptoModel.data![index].name.toString(), + cryptoModel.data![index].symbol.toString(), + 'USD', + [ + FlSpot(0, cryptoModel.data![index].metrics!.marketData!.ohlcvLast1Hour!.open), + FlSpot(2, cryptoModel.data![index].metrics!.marketData!.ohlcvLast1Hour!.high), + FlSpot(4, cryptoModel.data![index].metrics!.marketData!.ohlcvLast1Hour!.low), + FlSpot(5, cryptoModel.data![index].metrics!.marketData!.ohlcvLast1Hour!.close), + FlSpot(6, cryptoModel.data![index].metrics!.marketData!.priceUsd), + ], + themeData + ); + }, + + ), + ), + ) + ], + ); + } + else { + return SizedBox.shrink(); + } + } } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index c915153..5162649 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,21 +49,21 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "3.1.17" + version: "3.1.18" cloud_firestore_platform_interface: dependency: transitive description: name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.5.7" + version: "5.5.8" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.6.16" + version: "2.6.17" collection: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" equatable: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "2.0.0" file: dependency: transitive description: @@ -126,42 +126,42 @@ packages: name: firebase_auth url: "https://pub.dartlang.org" source: hosted - version: "3.3.19" + version: "3.3.20" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "6.2.7" + version: "6.2.8" firebase_auth_web: dependency: transitive description: name: firebase_auth_web url: "https://pub.dartlang.org" source: hosted - version: "3.3.16" + version: "3.3.17" firebase_core: dependency: transitive description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.17.1" + version: "1.18.0" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "4.4.1" firebase_core_web: dependency: transitive description: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.6.5" fl_chart: dependency: "direct main" description: @@ -180,7 +180,7 @@ packages: name: flutter_lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -206,7 +206,7 @@ packages: source: hosted version: "3.0.1" http: - dependency: transitive + dependency: "direct main" description: name: http url: "https://pub.dartlang.org" @@ -239,7 +239,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.0.0" matcher: dependency: transitive description: @@ -267,7 +267,7 @@ packages: name: page_transition url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.7" path: dependency: transitive description: @@ -281,28 +281,28 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.10" + version: "2.0.11" path_provider_android: dependency: transitive description: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.14" + version: "2.0.15" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.10" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.6" + version: "2.1.7" path_provider_macos: dependency: transitive description: @@ -323,7 +323,7 @@ packages: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.1.0" platform: dependency: transitive description: @@ -405,7 +405,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" unicons: dependency: "direct main" description: @@ -433,7 +433,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" xdg_directories: dependency: transitive description: @@ -443,4 +443,4 @@ packages: version: "0.2.0+1" sdks: dart: ">=2.17.0 <3.0.0" - flutter: ">=2.10.0-0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 7c69261..7f213cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,6 +43,7 @@ dependencies: crypto_font_icons: ^1.0.1 cloud_firestore: ^3.1.17 animated_splash_screen: ^1.2.0 + http: ^0.13.4 dev_dependencies: flutter_test: @@ -53,7 +54,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^1.0.0 + flutter_lints: ^2.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From 4492e33d293d1eff3020172a257fcdff6854cd35 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 21 Jun 2022 17:40:17 +0300 Subject: [PATCH 2/2] last updates --- lib/pages/home_page.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index ddf87a9..9e4eade 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -19,11 +19,7 @@ class AppScreen extends StatefulWidget { class _AppScreenState extends State { - var last1hour = 0; - var last1day = 1; - var last1week = 2; - var last1month = 3; - var last1year = 4; + bool iconBool = false; IconData iconLight = Icons.wb_sunny;