From ccefd5c2e4ab9a8f56506d39156e429705515817 Mon Sep 17 00:00:00 2001 From: Shaz hemani Date: Tue, 15 Dec 2020 16:01:27 +0500 Subject: [PATCH] health stream, pie chart, transaction history and more --- lib/main.dart | 2 + lib/models/healthSteam.dart | 9 +- lib/models/transaction.dart | 27 + lib/models/wallet.dart | 10 +- lib/providers/transaction_provider.dart | 40 ++ lib/providers/user_provider.dart | 12 + lib/repository/transaction.repository.dart | 46 ++ lib/repository/wallet.repository.dart | 25 +- lib/screens/dashboard/dashboard.dart | 54 +- lib/screens/history/history.dart | 106 +++- .../local_widgets/transaction_list_tile.dart | 52 ++ lib/screens/home/home.dart | 478 +++++++++--------- .../home/local_widgets/expenses_chart.dart | 107 ++++ .../financial_health_stream.dart | 137 +++++ lib/utils/helpers.dart | 13 + pubspec.lock | 21 + pubspec.yaml | 2 + 17 files changed, 841 insertions(+), 300 deletions(-) create mode 100644 lib/models/transaction.dart create mode 100644 lib/providers/transaction_provider.dart create mode 100644 lib/repository/transaction.repository.dart create mode 100644 lib/screens/history/local_widgets/transaction_list_tile.dart create mode 100644 lib/screens/home/local_widgets/expenses_chart.dart create mode 100644 lib/screens/home/local_widgets/financial_health_stream.dart create mode 100644 lib/utils/helpers.dart diff --git a/lib/main.dart b/lib/main.dart index bce60f2..c7d4d74 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'package:provider/provider.dart'; import 'providers/auth_provider.dart'; import 'providers/user_provider.dart'; import 'providers/wallet_provider.dart'; +import 'providers/transaction_provider.dart'; import 'package:robo_advisory/config/Routes.dart'; import 'package:robo_advisory/injection/dependency_injection.dart'; @@ -20,6 +21,7 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider(create: (_) => AuthProvider()), ChangeNotifierProvider(create: (_) => UserProvider()), ChangeNotifierProvider(create: (_) => WalletProvider()), + ChangeNotifierProvider(create: (_) => TransactionProvider()), ], child: MaterialApp( initialRoute: Routes.login, diff --git a/lib/models/healthSteam.dart b/lib/models/healthSteam.dart index 3b3571f..373d02a 100644 --- a/lib/models/healthSteam.dart +++ b/lib/models/healthSteam.dart @@ -1,6 +1,6 @@ class HealthSteam { String type; - String valueInPercentage; + int valueInPercentage; String goldInGram; String goldPriceInTurkishLira; String oneGramGoldPriceInLira; @@ -12,4 +12,11 @@ class HealthSteam { this.goldPriceInTurkishLira, this.oneGramGoldPriceInLira, }); + + HealthSteam.fromJson(Map map) + : type = map["type"], + valueInPercentage = map["value_in_percentage"], + goldInGram = map["gold_in_gram"], + goldPriceInTurkishLira = map["gold_price_in_turkish_lira"], + oneGramGoldPriceInLira = map["one_gram_gold_price_in_turkish_lira"]; } diff --git a/lib/models/transaction.dart b/lib/models/transaction.dart new file mode 100644 index 0000000..1cef5d3 --- /dev/null +++ b/lib/models/transaction.dart @@ -0,0 +1,27 @@ +class Category { + String name; + String color; + Category({this.name, this.color}); + + Category.formJson(Map map) + : name = map["name"], + color = map["color"]; +} + +class Transaction { + String amount; + String description; + String date; + String name; + Category category; + + Transaction( + {this.amount, this.description, this.date, this.name, this.category}); + + Transaction.fromJson(Map map) + : category = Category.formJson(map["category"]), + amount = map["amount"], + description = map["description"], + name = map["name"], + date = map["date"]; +} diff --git a/lib/models/wallet.dart b/lib/models/wallet.dart index 544cbdc..51eed9f 100644 --- a/lib/models/wallet.dart +++ b/lib/models/wallet.dart @@ -1,3 +1,4 @@ +import 'dart:core'; import 'package:robo_advisory/models/healthSteam.dart'; import 'package:robo_advisory/models/expenses.dart'; @@ -7,7 +8,7 @@ class Wallet { String totalGoldInGram; String totalGoldInTurkishLira; String healthSteamDay; - List healthStream; + List healthStreams; List expensesChart; Wallet({ @@ -16,7 +17,7 @@ class Wallet { this.totalGoldInGram, this.totalGoldInTurkishLira, this.healthSteamDay, - this.healthStream, + this.healthStreams, this.expensesChart, }); @@ -25,5 +26,8 @@ class Wallet { totalTurkishLiraPool = map["total_turkish_lira"], totalGoldInGram = map["total_gold_in_gram"], totalGoldInTurkishLira = map["total_gold_in_turkish_lira"], - healthSteamDay = map["health_stream_day"]; + healthSteamDay = map["health_stream_day"], + healthStreams = (map["health_stream"] as List) + .map((i) => HealthSteam.fromJson(i)) + .toList(); } diff --git a/lib/providers/transaction_provider.dart b/lib/providers/transaction_provider.dart new file mode 100644 index 0000000..cdc9e94 --- /dev/null +++ b/lib/providers/transaction_provider.dart @@ -0,0 +1,40 @@ +import 'package:flutter/foundation.dart'; +import 'package:robo_advisory/models/transaction.dart'; +import 'package:robo_advisory/repository/transaction.repository.dart'; + +class TransactionProvider with ChangeNotifier { + String _selectedCategory = "All"; + List _transactionsData; + List _transactionsList; + + List get transactionList { + if (_selectedCategory != 'All') { + return _transactionsList = _transactionsData + .where((transaction) => + transaction.category.name == _selectedCategory.toLowerCase()) + .toList(); + } else { + return _transactionsList = _transactionsData; + } + } + + void setTransactionsList(List transactions) { + _transactionsData = transactions; + _transactionsList = transactions; + notifyListeners(); + } + + String get selectedCategory => _selectedCategory; + + void setSelectedCategory(String category) { + _selectedCategory = category; + print(_selectedCategory); + notifyListeners(); + } + + Future> loadTransactions() async { + return (await TransactionRepository.loadTransactions() as List) + .map((i) => Transaction.fromJson(i)) + .toList(); + } +} diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index fd57904..dff068a 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -3,9 +3,21 @@ import 'package:robo_advisory/models/user.dart'; class UserProvider with ChangeNotifier { User _user = new User(); + int _selectedTabIndex = 0; + + List _categories = ["All", "Workplace", "Equipment", "Home", "Other"]; + + List get categories => _categories; User get user => _user; + int get selectedTabIndex => _selectedTabIndex; + + void setSelectedTabIndex(int index) { + _selectedTabIndex = index; + notifyListeners(); + } + void setUser(User user) { _user = user; notifyListeners(); diff --git a/lib/repository/transaction.repository.dart b/lib/repository/transaction.repository.dart new file mode 100644 index 0000000..0d6e820 --- /dev/null +++ b/lib/repository/transaction.repository.dart @@ -0,0 +1,46 @@ +import 'package:robo_advisory/injection/dependency_injection.dart'; + +class TransactionRepository { + static loadTransactions() async { + switch (Injector.checkInjector()) { + case Flavor.MOCK: + return transactionJSON["dataKey"]; + default: + // TODO: check how it will work with the API + return transactionJSON["dataKey"]; + } + } +} + +final transactionJSON = { + "dataKey": [ + { + "date": "2020-12-09", + "name": "Transaction 1", + "amount": "20", + "description": "lorem ipsum dolor sit", + "category": {"name": "workplace", "color": "#0293ee"} + }, + { + "date": "2020-12-01", + "name": "Transaction 2", + "amount": "23", + "description": "lorem ipsum dolor sit", + "category": {"name": "equipment", "color": "#f8b250"} + }, + { + "date": "2020-12-01", + "name": "Transaction 3", + "amount": "23", + "description": "lorem ipsum dolor sit", + "category": {"name": "home", "color": "#13d38e"} + }, + { + "date": "2020-12-01", + "name": "Transaction 4", + "amount": "23", + "description": "lorem ipsum dolor sit", + "category": {"name": "other", "color": "#845bef"} + } + ] +}; diff --git a/lib/repository/wallet.repository.dart b/lib/repository/wallet.repository.dart index cdb7731..44aca26 100644 --- a/lib/repository/wallet.repository.dart +++ b/lib/repository/wallet.repository.dart @@ -18,5 +18,28 @@ final wallerJSON = { 'total_turkish_lira': '5000.00 TL', 'total_gold_in_gram': '90.00g XAU', 'total_gold_in_turkish_lira': '45,000.00 TL', - 'health_stream_day': 'Day 01' + 'health_stream_day': 'Day 01', + 'health_stream': [ + { + "type": "Loss", + "value_in_percentage": 30, + "gold_in_gram": "90.00 gXAU", + "gold_price_in_turkish_lira": "50,000.00 TL", + "one_gram_gold_price_in_turkish_lira": "555.55 TL" + }, + { + "type": "Equal", + "value_in_percentage": 50, + "gold_in_gram": "90.00 gXAU", + "gold_price_in_turkish_lira": "50,000.00 TL", + "one_gram_gold_price_in_turkish_lira": "555.55 TL" + }, + { + "type": "Gain", + "value_in_percentage": 20, + "gold_in_gram": "90.00 gXAU", + "gold_price_in_turkish_lira": "50,000.00 TL", + "one_gram_gold_price_in_turkish_lira": "555.55 TL" + } + ] }; diff --git a/lib/screens/dashboard/dashboard.dart b/lib/screens/dashboard/dashboard.dart index f1c577c..404955a 100644 --- a/lib/screens/dashboard/dashboard.dart +++ b/lib/screens/dashboard/dashboard.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:robo_advisory/models/wallet.dart'; +import 'package:robo_advisory/providers/user_provider.dart'; import 'package:robo_advisory/screens/dashboard/local_widgets/bottom_navigation.dart'; import 'package:robo_advisory/screens/home/home.dart'; import 'package:robo_advisory/screens/fund_transfer/fund_transfer.dart'; @@ -7,11 +7,6 @@ import 'package:robo_advisory/screens/settlement/settlement.dart'; import 'package:robo_advisory/screens/history/history.dart'; import 'package:robo_advisory/widgets/drawer.dart'; import 'package:provider/provider.dart'; -import 'package:robo_advisory/providers/wallet_provider.dart'; -import 'package:flutter_spinkit/flutter_spinkit.dart'; - -// TODO: temp -import 'dart:async'; class DashboardScreen extends StatefulWidget { @override @@ -25,39 +20,19 @@ class _DashboardScreenState extends State { _scaffoldKey.currentState.openEndDrawer(); } - int _selectedIndex = 0; - bool loadingData = true; - Wallet walletData; - - void _onItemTapped(int index) { - setState(() { - _selectedIndex = index; - }); - } - - void initState() { - WalletProvider walletProvider = - Provider.of(context, listen: false); - walletProvider.loadWallet().then((value) { - if (value.totalAssets != null) { - Timer(Duration(seconds: 3), () { - setState(() { - loadingData = false; - walletData = value; - }); - print(value.totalAssets); - }); - } - }); - super.initState(); - } - @override Widget build(BuildContext context) { + int _selectedIndex = + Provider.of(context, listen: true).selectedTabIndex; + + void _onItemTapped(int index) { + Provider.of(context, listen: false) + .setSelectedTabIndex(index); + } + var currentTab = [ HomeScreen( toggleDrawer: _openEndDrawer, - wallet: walletData, ), FundTransferScreen(), SettlementScreen(), @@ -66,16 +41,7 @@ class _DashboardScreenState extends State { return Scaffold( key: _scaffoldKey, backgroundColor: Colors.white, - body: loadingData - ? Container( - child: Center( - child: SpinKitFadingFour( - color: Colors.black, - size: 100.0, - ), - ), - ) - : currentTab[_selectedIndex], + body: currentTab[_selectedIndex], endDrawer: AppDrawer(), bottomNavigationBar: BottomNavigation( selectedIndex: _selectedIndex, diff --git a/lib/screens/history/history.dart b/lib/screens/history/history.dart index 0e6e864..e62ba63 100644 --- a/lib/screens/history/history.dart +++ b/lib/screens/history/history.dart @@ -1,12 +1,110 @@ import 'package:flutter/material.dart'; +import 'package:robo_advisory/providers/user_provider.dart'; +import 'package:robo_advisory/theme/theme.dart'; +import 'package:provider/provider.dart'; +import 'package:robo_advisory/models/transaction.dart'; +import 'package:robo_advisory/providers/transaction_provider.dart'; +import 'package:robo_advisory/screens/history/local_widgets/transaction_list_tile.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; + +// TODO: temp +import 'dart:async'; + +class HistoryScreen extends StatefulWidget { + @override + _HistoryScreenState createState() => _HistoryScreenState(); +} + +class _HistoryScreenState extends State { + bool loadingData = true; + List transactionData; + + void initState() { + TransactionProvider transactionProvider = + Provider.of(context, listen: false); + transactionProvider.loadTransactions().then((value) { + if (value != null) { + Timer(Duration(seconds: 3), () { + setState(() { + loadingData = false; + transactionData = value; + Provider.of(context, listen: false) + .setTransactionsList(transactionData); + }); + }); + } + + print(value); + }); + super.initState(); + } -class HistoryScreen extends StatelessWidget { @override Widget build(BuildContext context) { + List transactionList = + Provider.of(context, listen: true).transactionList; return SafeArea( - child: Center( - child: Text('History Screen'), - ), + child: loadingData + ? Container( + child: Center( + child: SpinKitFadingFour( + color: Colors.black, + size: 100.0, + ), + ), + ) + : Padding( + padding: AppTheme.padding, + child: Column( + children: [ + Column( + children: [ + DropdownButton( + isExpanded: true, + items: Provider.of(context, listen: true) + .categories + .map((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + hint: new Text("Select Category"), + value: Provider.of(context, + listen: true) + .selectedCategory, + onChanged: (String newValue) { + Provider.of(context, + listen: false) + .setSelectedCategory(newValue); + }, + ) + ], + ), + SizedBox( + height: 20.0, + ), + Expanded( + child: transactionList.length != 0 + ? SingleChildScrollView( + child: ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: transactionList.length, + itemBuilder: (context, index) { + return TransactionListTile( + transactionObject: transactionList[index], + ); + }, + ), + ) + : Center( + child: Text('No Record Found'), + ), + ), + ], + ), + ), ); } } diff --git a/lib/screens/history/local_widgets/transaction_list_tile.dart b/lib/screens/history/local_widgets/transaction_list_tile.dart new file mode 100644 index 0000000..882189f --- /dev/null +++ b/lib/screens/history/local_widgets/transaction_list_tile.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; +import 'package:robo_advisory/models/transaction.dart'; +import 'package:robo_advisory/utils/helpers.dart'; + +class TransactionListTile extends StatelessWidget { + final Transaction transactionObject; + TransactionListTile({this.transactionObject}); + @override + Widget build(BuildContext context) { + return Column( + children: [ + Card( + margin: EdgeInsets.all(0), + color: Color(0xFFE5E5E5), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.0), + ), + child: ListTile( + leading: SizedBox( + height: double.infinity, + width: 3.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: HexColor(transactionObject.category.color), + ), + ), + ), + title: Transform.translate( + offset: Offset(-40, 0), + child: Text(transactionObject.name), + ), + subtitle: Transform.translate( + offset: Offset(-40, 0), + child: Text(transactionObject.description), + ), + trailing: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text("${transactionObject.amount} USD"), + Text(transactionObject.date) + ], + ), + ), + ), + SizedBox( + height: 20.0, + ) + ], + ); + } +} diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index 22987bc..14170fd 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -2,275 +2,259 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:robo_advisory/models/wallet.dart'; import 'package:robo_advisory/theme/theme.dart'; +import 'package:provider/provider.dart'; +import 'package:robo_advisory/providers/wallet_provider.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'package:robo_advisory/screens/home/local_widgets/financial_health_stream.dart'; +import 'package:robo_advisory/screens/home/local_widgets/expenses_chart.dart'; -class HomeScreen extends StatelessWidget { - HomeScreen({@required this.toggleDrawer, @required this.wallet}); +// TODO: temp +import 'dart:async'; + +class HomeScreen extends StatefulWidget { + HomeScreen({@required this.toggleDrawer}); final Function toggleDrawer; - final Wallet wallet; - double calculatePercentage(double fullWidth, int percentValue) { - return (percentValue / 100) * fullWidth; + @override + _HomeScreenState createState() => _HomeScreenState(); +} + +class _HomeScreenState extends State { + bool loadingData = true; + Wallet walletData; + + void initState() { + WalletProvider walletProvider = + Provider.of(context, listen: false); + walletProvider.loadWallet().then((value) { + if (value.totalAssets != null) { + Timer(Duration(seconds: 3), () { + setState(() { + loadingData = false; + walletData = value; + }); + }); + } + }); + super.initState(); } @override Widget build(BuildContext context) { - return SingleChildScrollView( - child: Center( - child: SafeArea( - child: Padding( - padding: AppTheme.padding, - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Hi Johne', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 36.0, - color: Colors.black, - ), - ), - ), - GestureDetector( - onTap: toggleDrawer, - child: Icon(Icons.more_vert), - ), - ], - ), - SizedBox( - height: 30.0, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - alignment: Alignment.centerLeft, - width: double.infinity, - padding: EdgeInsets.all(20.0), - color: Color(0xFFC4C4C4), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Total Assets', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - Text( - wallet.totalAssets, - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 45, - color: Colors.black, - ), - ), - ), - ], - ), - ), - Container( - padding: EdgeInsets.only( - left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), - color: Color(0xFFE5E5E5), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'TRY pool', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - Text( - wallet.totalTurkishLiraPool, - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - ], - ), - ), - Container( - padding: EdgeInsets.only( - left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), - color: Color(0xFFC4C4C4), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Total XAU grams', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - Text( - wallet.totalGoldInGram, - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - ], - ), - ), - ], - ), - SizedBox( - height: 30.0, - ), - Container( - width: double.infinity, - padding: EdgeInsets.only( - left: 20.0, right: 20.0, top: 7.0, bottom: 20.0), - color: Color(0xFFE5E5E5), + return loadingData + ? Container( + child: Center( + child: SpinKitFadingFour( + color: Colors.black, + size: 100.0, + ), + ), + ) + : SingleChildScrollView( + child: Center( + child: SafeArea( + child: Padding( + padding: AppTheme.padding, child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - 'Financial Health Stream', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Hi Johne', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 36.0, + color: Colors.black, + ), + ), ), - ), + GestureDetector( + onTap: widget.toggleDrawer, + child: Icon(Icons.more_vert), + ), + ], ), SizedBox( - height: 10.0, + height: 30.0, ), - Row( + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox( - width: calculatePercentage( - MediaQuery.of(context).size.width - 100, 30), - height: 5.0, - child: const DecoratedBox( - decoration: const BoxDecoration( - color: Color(0xFF892626), - ), + Container( + alignment: Alignment.centerLeft, + width: double.infinity, + padding: EdgeInsets.all(20.0), + color: Color(0xFFC4C4C4), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Total Assets', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + Text( + walletData.totalAssets, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 45, + color: Colors.black, + ), + ), + ), + ], + ), + ), + Container( + padding: EdgeInsets.only( + left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), + color: Color(0xFFE5E5E5), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'TRY pool', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + Text( + walletData.totalTurkishLiraPool, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + ], + ), + ), + Container( + padding: EdgeInsets.only( + left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), + color: Color(0xFFC4C4C4), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Total XAU grams', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + Text( + walletData.totalGoldInGram, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + ], + ), + ), + ], + ), + SizedBox( + height: 30.0, + ), + FinancialHealthStream( + healthSteams: walletData.healthStreams), + SizedBox( + height: 30.0, + ), + Column( + children: [ + Container( + padding: EdgeInsets.only( + left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), + color: Color(0xFFE5E5E5), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'TRY pool', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + Text( + walletData.totalGoldInTurkishLira, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Color(0xFF896126), + ), + ), + ), + ], + ), + ), + Container( + padding: EdgeInsets.only( + left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), + color: Color(0xFFC4C4C4), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Total XAU grams', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + Text( + walletData.totalGoldInGram, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 16, + color: Colors.black, + ), + ), + ), + ], ), ), SizedBox( - width: calculatePercentage( - MediaQuery.of(context).size.width - 100, 50), - height: 5.0, - child: const DecoratedBox( - decoration: const BoxDecoration( - color: Color(0xFF896126), - ), - ), + height: 20.0, ), - SizedBox( - width: calculatePercentage( - MediaQuery.of(context).size.width - 100, 20), - height: 5.0, - child: const DecoratedBox( - decoration: const BoxDecoration( - color: Color(0xFF348926), - ), - ), - ) + ExpensesChart() ], ) ], ), ), - SizedBox( - height: 30.0, - ), - Column( - children: [ - Container( - padding: EdgeInsets.only( - left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), - color: Color(0xFFE5E5E5), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'TRY pool', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - Text( - wallet.totalGoldInTurkishLira, - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Color(0xFF896126), - ), - ), - ), - ], - ), - ), - Container( - padding: EdgeInsets.only( - left: 20.0, right: 20.0, top: 7.0, bottom: 7.0), - color: Color(0xFFC4C4C4), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Total XAU grams', - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - Text( - wallet.totalGoldInGram, - style: GoogleFonts.inter( - textStyle: TextStyle( - fontWeight: FontWeight.normal, - fontSize: 16, - color: Colors.black, - ), - ), - ), - ], - ), - ), - ], - ) - ], + ), ), - ), - ), - ), - ); + ); } } diff --git a/lib/screens/home/local_widgets/expenses_chart.dart b/lib/screens/home/local_widgets/expenses_chart.dart new file mode 100644 index 0000000..2db1054 --- /dev/null +++ b/lib/screens/home/local_widgets/expenses_chart.dart @@ -0,0 +1,107 @@ +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:robo_advisory/providers/transaction_provider.dart'; +import 'package:robo_advisory/providers/user_provider.dart'; + +class ExpensesChart extends StatefulWidget { + @override + State createState() => ExpensesChartState(); +} + +class ExpensesChartState extends State { + int touchedIndex; + + @override + Widget build(BuildContext context) { + List categories = + Provider.of(context, listen: true).categories; + return Row( + children: [ + Expanded( + child: PieChart( + PieChartData( + pieTouchData: PieTouchData(touchCallback: (pieTouchResponse) { + setState(() { + if (pieTouchResponse.touchInput is FlLongPressEnd || + pieTouchResponse.touchInput is FlPanEnd) { + touchedIndex = -1; + } else { + touchedIndex = pieTouchResponse.touchedSectionIndex; + if (touchedIndex != null) { + Provider.of(context, listen: false) + .setSelectedTabIndex(3); + Provider.of(context, listen: false) + .setSelectedCategory(categories[touchedIndex + 1]); + } + } + }); + }), + borderData: FlBorderData( + show: false, + ), + sectionsSpace: 1, + centerSpaceRadius: 70, + sections: showingSections()), + ), + ), + ], + ); + } + + List showingSections() { + return List.generate(4, (i) { + final isTouched = i == touchedIndex; + final double fontSize = isTouched ? 25 : 16; + final double radius = isTouched ? 60 : 50; + switch (i) { + case 0: + return PieChartSectionData( + color: const Color(0xff0293ee), + value: 50, + title: '50%', + radius: radius, + titleStyle: TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.bold, + color: const Color(0xffffffff)), + ); + case 1: + return PieChartSectionData( + color: const Color(0xfff8b250), + value: 12, + title: '12%', + radius: radius, + titleStyle: TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.bold, + color: const Color(0xffffffff)), + ); + case 2: + return PieChartSectionData( + color: const Color(0xff13d38e), + value: 13, + title: '13%', + radius: radius, + titleStyle: TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.bold, + color: const Color(0xffffffff)), + ); + case 3: + return PieChartSectionData( + color: const Color(0xff845bef), + value: 25, + title: '25%', + radius: radius, + titleStyle: TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.bold, + color: const Color(0xffffffff)), + ); + default: + return null; + } + }); + } +} diff --git a/lib/screens/home/local_widgets/financial_health_stream.dart b/lib/screens/home/local_widgets/financial_health_stream.dart new file mode 100644 index 0000000..a9343b0 --- /dev/null +++ b/lib/screens/home/local_widgets/financial_health_stream.dart @@ -0,0 +1,137 @@ +import 'package:flutter/material.dart'; +import 'package:robo_advisory/models/healthSteam.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; + +class FinancialHealthStream extends StatelessWidget { + FinancialHealthStream({@required this.healthSteams}); + final List healthSteams; + + double calculatePercentage(double fullWidth, int percentValue) { + return (percentValue / 100) * fullWidth; + } + + @override + Widget build(BuildContext context) { + YYDialog.init(context); + return Container( + width: double.infinity, + padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 7.0, bottom: 10.0), + color: Color(0xFFE5E5E5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Financial Health Stream', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 18, + color: Colors.black, + ), + ), + ), + SizedBox( + height: 3.0, + ), + Text( + 'Day 01', + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 12, + color: Colors.black, + ), + ), + ), + SizedBox( + height: 10.0, + ), + new LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Row( + children: healthSteams + .asMap() + .map((index, healthStream) => MapEntry( + index, + healthStreamBar(context, healthStream, index, + constraints.maxWidth))) + .values + .toList() + // + ); + }), + ], + ), + ); + } + + GestureDetector healthStreamBar(BuildContext context, HealthSteam healthSteam, + int index, double widthOFRow) { + final List healthSteamColors = [ + Color(0xFF892626), + Color(0xFF896126), + Color(0xFF348926) + ]; + return GestureDetector( + onTap: () { + YYDialog().build(context) + ..backgroundColor = healthSteamColors[index] + ..width = 140 + ..borderRadius = 4.0 + ..text( + padding: EdgeInsets.only(top: 10.0), + alignment: Alignment.center, + text: healthSteam.goldInGram, + color: Colors.white, + fontSize: 14.0, + fontWeight: FontWeight.w500, + ) + ..text( + alignment: Alignment.center, + text: healthSteam.goldPriceInTurkishLira, + color: Colors.white, + fontSize: 14.0, + fontWeight: FontWeight.w500, + ) + ..text( + padding: EdgeInsets.only(bottom: 10.0), + alignment: Alignment.center, + text: "1.00g = " + healthSteam.oneGramGoldPriceInLira, + color: Colors.white, + fontSize: 14.0, + fontWeight: FontWeight.w500, + ) + ..show(); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: + calculatePercentage(widthOFRow, healthSteam.valueInPercentage), + height: 5.0, + child: DecoratedBox( + decoration: BoxDecoration( + color: healthSteamColors[index], + ), + ), + ), + SizedBox( + height: 3.0, + ), + Text( + healthSteam.type, + style: GoogleFonts.inter( + textStyle: TextStyle( + fontWeight: FontWeight.normal, + fontSize: 12, + color: Colors.black, + ), + ), + ) + ], + ), + ); + } +} diff --git a/lib/utils/helpers.dart b/lib/utils/helpers.dart new file mode 100644 index 0000000..dd7e7c4 --- /dev/null +++ b/lib/utils/helpers.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class HexColor extends Color { + static int _getColorFromHex(String hexColor) { + hexColor = hexColor.toUpperCase().replaceAll("#", ""); + if (hexColor.length == 6) { + hexColor = "FF" + hexColor; + } + return int.parse(hexColor, radix: 16); + } + + HexColor(final String hexColor) : super(_getColorFromHex(hexColor)); +} diff --git a/pubspec.lock b/pubspec.lock index 911a441..2378cd9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,6 +64,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" + equatable: + dependency: transitive + description: + name: equatable + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.5" fake_async: dependency: transitive description: @@ -85,11 +92,25 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.2.1" + fl_chart: + dependency: "direct main" + description: + name: fl_chart + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_custom_dialog: + dependency: "direct main" + description: + name: flutter_custom_dialog + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.20" flutter_spinkit: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index dc06239..898019a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,8 @@ dependencies: pin_code_fields: ^6.0.1 flutter_svg: ^0.19.1 google_fonts: ^1.1.1 + fl_chart: ^0.12.0 + flutter_custom_dialog: ^1.0.20 dev_dependencies: flutter_test: sdk: flutter