From 9307681225cec3ec447746ba80381e070f0df4e8 Mon Sep 17 00:00:00 2001 From: Sewmina Dilshan Date: Thu, 9 Feb 2023 14:56:47 +0530 Subject: [PATCH] Wallet wip --- lib/Backend/brains.dart | 21 ++++ lib/Backend/helpers.dart | 38 ++++++ lib/Backend/hoarder.dart | 1 + lib/Backend/login_mgr.dart | 1 + lib/home.dart | 247 ++++++++++++++++++++++++++++++++----- lib/main.dart | 6 +- lib/splash.dart | 3 +- pubspec.lock | 32 +++++ pubspec.yaml | 3 + 9 files changed, 317 insertions(+), 35 deletions(-) create mode 100644 lib/Backend/helpers.dart diff --git a/lib/Backend/brains.dart b/lib/Backend/brains.dart index 028474b..01cd713 100644 --- a/lib/Backend/brains.dart +++ b/lib/Backend/brains.dart @@ -1,6 +1,27 @@ +import 'package:faucethub/Backend/DebugHelper.dart'; +import 'package:faucethub/Backend/hoarder.dart'; + class Brain{ static const String API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/api/"; static dynamic UserJson; + + static List LinkedGamesJson = []; + static List NonLinkedGamesJson = []; + + + static void InitUserData(){ + LinkedGamesJson = []; + NonLinkedGamesJson = []; + List linkedGames = UserJson['linkedGames'].toString().split(','); + Debug.Log("Going to filter linked games from ${Hoarder.GamesJson.length} games\nmy linked game ids : ${UserJson['linkedGames']}"); + Hoarder.GamesJson.forEach((game) { + if(linkedGames.contains(game['id'])){ + LinkedGamesJson.add(game); + }else{ + NonLinkedGamesJson.add(game); + } + }); + } } \ No newline at end of file diff --git a/lib/Backend/helpers.dart b/lib/Backend/helpers.dart new file mode 100644 index 0000000..d9f2ddf --- /dev/null +++ b/lib/Backend/helpers.dart @@ -0,0 +1,38 @@ +import 'package:crypto_font_icons/crypto_font_icons.dart'; +import 'package:faucethub/Backend/hoarder.dart'; +import 'package:flutter/material.dart'; + +class Helpers{ + + static IconData GetIconForCrypto(String val){ + switch(val){ + case "BTC": + return CryptoFontIcons.BTC; + break; + case "ETH": + return CryptoFontIcons.ETH; + break; + case "XRP": + return CryptoFontIcons.XRP; + break; + case "DOGE": + return CryptoFontIcons.DOGE; + break; + case "LTC": + return CryptoFontIcons.LTC; + break; + } + + return CryptoFontIcons.BTC; + } + + static String GetIconForGame(String name){ + Hoarder.GamesJson.forEach((element) { + if(element['name'] == name){ + return element['thumbnail']; + } + }); + + return ""; + } +} \ No newline at end of file diff --git a/lib/Backend/hoarder.dart b/lib/Backend/hoarder.dart index 99b67d9..d15d38e 100644 --- a/lib/Backend/hoarder.dart +++ b/lib/Backend/hoarder.dart @@ -7,6 +7,7 @@ import 'package:http/http.dart' as http; class Hoarder{ static List GamesJson = []; + static Map Settings = {}; static List FeaturedGames = []; diff --git a/lib/Backend/login_mgr.dart b/lib/Backend/login_mgr.dart index c032141..174bf75 100644 --- a/lib/Backend/login_mgr.dart +++ b/lib/Backend/login_mgr.dart @@ -75,6 +75,7 @@ class LoginManager { try{ Brain.UserJson = jsonDecode(loginResponse.body.toString()); + Brain.InitUserData(); Debug.LogResponse(Brain.UserJson); prefs.setString("username", username); prefs.setString("password", password); diff --git a/lib/home.dart b/lib/home.dart index 5490219..71f8f82 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -1,9 +1,13 @@ +// import 'package:crypto_font_icons/crypto_font_icons.dart'; +import 'package:crypto_font_icons/crypto_font_icons.dart'; import 'package:faucethub/Backend/DebugHelper.dart'; import 'package:faucethub/Backend/brains.dart'; import 'package:faucethub/Backend/hoarder.dart'; import 'package:faucethub/Backend/login_mgr.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'Backend/helpers.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -15,29 +19,37 @@ class HomePage extends StatefulWidget { int selectedBotNavIndex = 0; class _HomePageState extends State { - static List bodyOptions = [ - HomeWidget(), - GamesWidget(), - Text("Money!") - ]; - static Widget HomeWidget() { + @override + void initState() { + // TODO: implement initState + super.initState(); + + } + + Widget HomeWidget() { final ScrollController _firstController = ScrollController(); return SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( - padding: EdgeInsets.all(10), + padding: EdgeInsets.all(20), child: Text("Welcome ${Brain.UserJson['name']},", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), ), - SizedBox( - height: 20, - ), - HomeCard(child: Container(padding:EdgeInsets.symmetric(vertical: 50),child: Text("\$6.90", style: TextStyle(fontSize: 50),),), title: "Earnings"), - HomeCard(title:"Featured Games",child: - SizedBox( + HomeCard( + child: Container( + padding: EdgeInsets.symmetric(vertical: 50), + child: Text( + "\$6.90", + style: TextStyle(fontSize: 50), + ), + ), + title: "Earnings"), + HomeCard( + title: "Featured Games", + child: SizedBox( height: 110, child: Scrollbar( thumbVisibility: true, @@ -49,12 +61,14 @@ class _HomePageState extends State { itemBuilder: (BuildContext context, int index) { Debug.Log(Hoarder.FeaturedGames[index]); return InkWell( - onTap: (){}, + onTap: () {}, child: Card( child: ClipRRect( borderRadius: BorderRadius.circular(12), - child: Image.network(Hoarder.FeaturedGames[index]['icon'], - width: 100, height: 100), + child: Image.network( + Hoarder.FeaturedGames[index]['icon'], + width: 100, + height: 100), ), ), ); @@ -62,34 +76,93 @@ class _HomePageState extends State { ), ), ), - HomeCard(child: SizedBox(height: 250,), title: "Top Players"), - + HomeCard( + child: SizedBox( + height: 250, + ), + title: "Top Players"), ], ), ); } - static Widget GamesWidget(){ + Widget GamesWidget() { final ScrollController scrollController = ScrollController(); return Container( + padding: EdgeInsets.fromLTRB(20, 20, 0, 20), child: SingleChildScrollView( physics: ScrollPhysics(), child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text("Linked", style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),), + Text( + "Linked", + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + SizedBox( + height: 5, + ), ListView.builder( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, controller: scrollController, - itemCount: Hoarder.GamesJson.length, + itemCount: Brain.LinkedGamesJson.length, itemBuilder: (BuildContext context, int index) { - Debug.Log(Hoarder.GamesJson[index]); + // Debug.Log(Hoarder.LinkedGamesJson[index]); return InkWell( - onTap: (){}, + onTap: () {}, child: ListTile( - leading: Image.network(Hoarder.GamesJson[index]['icon'], - width: 25, height: 25), - title: Text(Hoarder.GamesJson[index]['name']), + leading: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.network(Brain.LinkedGamesJson[index]['icon'], + width: 50, height: 50), + ), + title: Text(Brain.LinkedGamesJson[index]['name']), + subtitle: Text(Brain.LinkedGamesJson[index]['description']), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Helpers.GetIconForCrypto( + Brain.LinkedGamesJson[index]['coin']), + size: 17, + ), + SizedBox( + width: 2, + ), + Text("0.00004000"), + ], + ), + ), + ); + }), + SizedBox( + height: 20, + ), + Text( + "Not Linked", + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + SizedBox( + height: 5, + ), + ListView.builder( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + controller: scrollController, + itemCount: Brain.NonLinkedGamesJson.length, + itemBuilder: (BuildContext context, int index) { + // Debug.Log(Hoarder.NonLinkedGamesJson[index]); + return InkWell( + onTap: () {}, + child: ListTile( + leading: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.network(Brain.NonLinkedGamesJson[index]['icon'], + width: 50, height: 50), + ), + title: Text(Brain.NonLinkedGamesJson[index]['name']), + subtitle: Text(Brain.NonLinkedGamesJson[index]['description']), ), ); }) @@ -99,20 +172,109 @@ class _HomePageState extends State { ); } + Widget WalletWidget() { + final ScrollController scrollController = ScrollController(); + return Container( + padding: EdgeInsets.all(10), + child: + Container( child: Column(children: [ + HomeCard(child: Container( + child: ListTile( + leading: FaIcon(FontAwesomeIcons.solidCircleUser,size: 60,), + title: Text(Brain.UserJson['name']), + subtitle: Text("Total Earnings : \$42.69"), + trailing: IconButton(icon: Icon(Icons.settings), onPressed: () { selectedBotNavIndex=3;setState(() { + + }); },), + ) + ), title: "Your Account", showMore: false), + Row(mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max,children: [ + Expanded(child: MaterialButton(onPressed: (){}, child: Text("Withdraw"),color: Colors.green, )) + ],), + SizedBox(height: 30,), + Text("Sort by",style: TextStyle(fontSize: 12),), + DefaultTabController(length: 2, child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + + TabBar( + tabs:[Tab(text: "Currency",),Tab(text: "Games",)] + ), + + Container( + padding: EdgeInsets.all(10), + //Add this to give height + constraints: BoxConstraints.expand(height: 250), + child: TabBarView(children: [ + Container( + child: Column( + + children: [ + CurrencyListItem("BTC", "0.0004000 = \$1.20"), + CurrencyListItem("ETH", "0.0004000 = \$0.50"), + CurrencyListItem("XRP", "0.0004000 = \$0.20"), + CurrencyListItem("DOGE", "0.0004000 = \$0.020") + + ], + ) + ), + Container( + child: Column( + children: [ + GameListItem(Hoarder.GamesJson[0], "0.0004000 = \$1.20"), + GameListItem(Hoarder.GamesJson[1], "0.0004000 = \$1.20"), + GameListItem(Hoarder.GamesJson[2], "0.0004000 = \$1.20"), + + ], + ) + ), + ]), + ), + + ], + )) + ],))); + } + + Widget SettingsWidget() { + final ScrollController scrollController = ScrollController(); + return Container( + padding: EdgeInsets.symmetric(vertical: 20,horizontal: 10), + child: + SingleChildScrollView(physics: ScrollPhysics(), child: Column(children: [ + Text("Settings", style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold),), + SizedBox(height: 20,), + ListTile() + ],))); + } + @override Widget build(BuildContext context) { + List bodyOptions = [ + HomeWidget(), + GamesWidget(), + WalletWidget(), + SettingsWidget() + ]; + return SafeArea( child: Scaffold( // appBar: AppBar(title: Text('Faucet Hub'),), body: bodyOptions.elementAt(selectedBotNavIndex), bottomNavigationBar: BottomNavigationBar( + enableFeedback: true, + selectedItemColor: Colors.green, + unselectedItemColor: Colors.grey, + elevation: 20, items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"), BottomNavigationBarItem( icon: Icon(Icons.videogame_asset), label: "Games"), BottomNavigationBarItem( icon: Icon(Icons.account_balance_wallet), label: "Wallet"), + BottomNavigationBarItem( + icon: Icon(Icons.settings), label: "Settings"), ], currentIndex: selectedBotNavIndex, onTap: onBotNavTapped, @@ -120,7 +282,8 @@ class _HomePageState extends State { ); } - static Widget HomeCard({required Widget child, required String title}) { + static Widget HomeCard( + {bool showMore = false, required Widget child, required String title}) { return Padding( padding: const EdgeInsets.all(8.0), child: Card( @@ -135,11 +298,13 @@ class _HomePageState extends State { children: [ Text( title, - style: TextStyle(fontSize: 17,fontWeight: FontWeight.bold), + style: TextStyle( + fontSize: 17, fontWeight: FontWeight.bold), ), - InkWell(child: Icon(Icons.arrow_right_alt), onTap: (){ - - },) + (showMore) ? InkWell( + child: Icon(Icons.arrow_right_alt), + onTap: () {}, + ) : Container() ], ), ), @@ -147,6 +312,26 @@ class _HomePageState extends State { ])))); } + Widget CurrencyListItem(String currencyName, String value){ + return Container(padding: EdgeInsets.all(5), + child: Row(mainAxisSize: MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row(mainAxisSize: MainAxisSize.min, children: [Icon(Helpers.GetIconForCrypto(currencyName)),SizedBox(width: 10,), Text(currencyName)],), + Text(value) + ],), + ); + } + + Widget GameListItem(dynamic Game, String value){ + return Container(padding: EdgeInsets.all(5), + child: Row(mainAxisSize: MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row(mainAxisSize: MainAxisSize.min, children: [ Icon(Helpers.GetIconForCrypto(Game['coin'])),SizedBox(width: 10,), Text(Game['name'])],), + Text(value) + ],), + ); + } + void onBotNavTapped(int value) { selectedBotNavIndex = value; setState(() {}); diff --git a/lib/main.dart b/lib/main.dart index a87d29d..1a77caf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,9 +26,9 @@ class MyApp extends StatelessWidget { ), initialRoute: '/splash', routes: { - '/login': (context)=> const LoginPage(), - '/splash': (context)=> const SplashScreen(), - '/home': (context)=> const HomePage(), + '/login': (context)=> LoginPage(), + '/splash': (context)=> SplashScreen(), + '/home': (context)=> HomePage(), }, ); diff --git a/lib/splash.dart b/lib/splash.dart index 33787be..b256815 100644 --- a/lib/splash.dart +++ b/lib/splash.dart @@ -22,8 +22,9 @@ class _SplashScreenState extends State { } void init () async{ - int result = await LoginManager.AutoLogin(); await Hoarder.GrabInitData(); + + int result = await LoginManager.AutoLogin(); if(result == 0){ Navigator.of(context).pushReplacementNamed('/home'); }else{ diff --git a/pubspec.lock b/pubspec.lock index 3960b16..820a0c2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.0" + crypto_font_icons: + dependency: "direct main" + description: + name: crypto_font_icons + sha256: "682bfc120599c04ced0c3a8120aaaac1bfd0a7c2109d23a62bf6c832d1932452" + url: "https://pub.dev" + source: hosted + version: "1.0.1" cupertino_icons: dependency: "direct main" description: @@ -160,6 +168,14 @@ packages: description: flutter source: sdk version: "0.0.0" + font_awesome_flutter: + dependency: "direct main" + description: + name: font_awesome_flutter + sha256: "875dbb9ec1ad30d68102019ceb682760d06c72747c1c5b7885781b95f88569cc" + url: "https://pub.dev" + source: hosted + version: "10.3.0" google_sign_in: dependency: "direct main" description: @@ -437,6 +453,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + syncfusion_flutter_charts: + dependency: "direct main" + description: + name: syncfusion_flutter_charts + sha256: "400fa4c57a22f17b78fac6d086e39ecc7b7ece760fdf2041f235951f05640976" + url: "https://pub.dev" + source: hosted + version: "20.4.49" + syncfusion_flutter_core: + dependency: transitive + description: + name: syncfusion_flutter_core + sha256: b5cb2525beb38fae36a363f72f8a2db92ed3995d6f0695968412cc6836e3a7b7 + url: "https://pub.dev" + source: hosted + version: "20.4.49" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f85bf80..d3515dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,6 +18,9 @@ dependencies: http: ^0.13.5 shared_preferences: ^2.0.17 flutter_spinkit: ^5.1.0 + font_awesome_flutter: ^10.3.0 + crypto_font_icons: ^1.0.1 + syncfusion_flutter_charts: ^20.4.49 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.