From 837b104eb502ce90e04291d0926fe4f7dbbb88a1 Mon Sep 17 00:00:00 2001 From: Flavio Date: Sat, 13 Jun 2020 15:02:32 -0300 Subject: [PATCH] tab inferior e tela de dividendos --- lib/main.dart | 8 +-- lib/{ => models}/asset.dart | 0 lib/models/dividend.dart | 23 +++++++++ lib/{ => utils}/CEICredentials.dart | 2 +- lib/{ => utils}/appInitializer.dart | 2 +- lib/{ => utils}/storage.dart | 0 lib/utils/theme.dart | 6 +++ lib/views/dividends.dart | 79 +++++++++++++++++++++++++++++ lib/views/home.dart | 49 ++++++++++++++++++ lib/{ => views}/login.dart | 19 +++---- lib/{ => views}/portfolio.dart | 25 +++------ lib/{ => views}/splashScreen.dart | 2 +- pubspec.lock | 72 ++++++++++++++++++++------ 13 files changed, 234 insertions(+), 53 deletions(-) rename lib/{ => models}/asset.dart (100%) create mode 100644 lib/models/dividend.dart rename lib/{ => utils}/CEICredentials.dart (96%) rename lib/{ => utils}/appInitializer.dart (87%) rename lib/{ => utils}/storage.dart (100%) create mode 100644 lib/utils/theme.dart create mode 100644 lib/views/dividends.dart create mode 100644 lib/views/home.dart rename lib/{ => views}/login.dart (79%) rename lib/{ => views}/portfolio.dart (71%) rename lib/{ => views}/splashScreen.dart (85%) diff --git a/lib/main.dart b/lib/main.dart index cba350a..e271e24 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,8 @@ -import 'package:app/login.dart'; -import 'package:app/portfolio.dart'; +import 'package:app/views/login.dart'; +import 'package:app/views/home.dart'; import 'package:flutter/material.dart'; -import 'splashScreen.dart'; +import 'package:app/views/splashScreen.dart'; void main() async{ @@ -11,7 +11,7 @@ void main() async{ home: SplashScreen(), routes: { // Set routes for using the Navigator. - '/home': (BuildContext context) => new Portfolio(), + '/home': (BuildContext context) => new Home(), '/login': (BuildContext context) => new Login() }, ) diff --git a/lib/asset.dart b/lib/models/asset.dart similarity index 100% rename from lib/asset.dart rename to lib/models/asset.dart diff --git a/lib/models/dividend.dart b/lib/models/dividend.dart new file mode 100644 index 0000000..3b45a0e --- /dev/null +++ b/lib/models/dividend.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class Dividend { + + final String _fantasyName; + final String _ticker; + final String _type; + final String _date; + final String currency; + final String _netIncome; + + final Map _assetTypeIcons= { + "share": Icons.library_books, + "reit": Icons.location_city + }; + + Dividend(this._fantasyName, this._ticker, this._type, this._date, this._netIncome, {this.currency="R\$"}); + + String get name => _fantasyName + " (" + _ticker + ")"; + IconData get icon => _assetTypeIcons[this._type]; + String get date => _date; + String get income => "$currency$_netIncome"; +} \ No newline at end of file diff --git a/lib/CEICredentials.dart b/lib/utils/CEICredentials.dart similarity index 96% rename from lib/CEICredentials.dart rename to lib/utils/CEICredentials.dart index 7d25841..679f15a 100644 --- a/lib/CEICredentials.dart +++ b/lib/utils/CEICredentials.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'package:app/storage.dart'; +import 'package:app/utils/storage.dart'; class CEICredentials{ String _cpf; diff --git a/lib/appInitializer.dart b/lib/utils/appInitializer.dart similarity index 87% rename from lib/appInitializer.dart rename to lib/utils/appInitializer.dart index 3c97c9d..a842d9e 100644 --- a/lib/appInitializer.dart +++ b/lib/utils/appInitializer.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:app/CEICredentials.dart'; +import 'package:app/utils/CEICredentials.dart'; redirect(BuildContext context) async{ CEICredentials creds = CEICredentials.empty(); diff --git a/lib/storage.dart b/lib/utils/storage.dart similarity index 100% rename from lib/storage.dart rename to lib/utils/storage.dart diff --git a/lib/utils/theme.dart b/lib/utils/theme.dart new file mode 100644 index 0000000..b349eda --- /dev/null +++ b/lib/utils/theme.dart @@ -0,0 +1,6 @@ +import 'package:flutter/material.dart'; + +final biggerFont = const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold); +final normalFont = const TextStyle(fontSize: 18.0); +final smallerFont = const TextStyle(fontSize: 14.0, color: Colors.grey); +final buttonFont = const TextStyle(fontSize: 18.0, color: Colors.white); \ No newline at end of file diff --git a/lib/views/dividends.dart b/lib/views/dividends.dart new file mode 100644 index 0000000..6798eb4 --- /dev/null +++ b/lib/views/dividends.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:app/utils/theme.dart'; + +import '../models/dividend.dart'; + +class DividendsState extends State { + + final _provisioned = [ + Dividend("Energias do Brasil", "ENBR3", "share", "28/06/2020", "31,30"), + Dividend("KINEA RENDA IMOBILIÁRIA FDO INV IMOB", "KNRI11", "reit", "20/06/2020", "25,10"), + Dividend("Sinqia", "SQIA3", "share", "17/06/2020", "08,60") + ]; + + final _credited = [ + Dividend("Itaúsa", "ITSA4", "share", "10/06/2020", "10,20"), + Dividend("Fleury", "FLRY3", "share", "08/06/2020", "4,20"), + Dividend("B3", "B3SA3", "share", "02/06/2020", "15,50"), + Dividend("HSI MALL FDO INV IMOB", "HSML11", "reit", "01/06/2020", "20,60") + ]; + + @override + Widget build(BuildContext context) { + return _buildDividends(); + } + + Widget _buildDividends() { + return ListView.builder( + padding: const EdgeInsets.all(15), + itemBuilder: (context, i) { + if (i.isOdd) return Divider(); + int index = i ~/ 2; + + if (index == 0) return _buildTitle("Provisionado"); + index -= 1; + + if (index < _provisioned.length) return _buildRow(_provisioned[index]); + index -= _provisioned.length; + + if (index == 0) return _buildTitle("Creditado"); + index -= 1; + + if (index < _credited.length) return _buildRow(_credited[index]); + + return null; + }); + } + + Widget _buildTitle(text) { + return ListTile( + title: Text( + text, + style: biggerFont + ) + ); + } + + Widget _buildRow(Dividend dividend) { + return ListTile( + title: Text( + dividend.name, + style: biggerFont, + ), + subtitle: Text( + dividend.date, + style: smallerFont, + ), + leading: Icon(dividend.icon), + trailing: Text( + dividend.income, + style: normalFont, + ) + ); + } +} + +class Dividends extends StatefulWidget { + @override + DividendsState createState() => DividendsState(); +} diff --git a/lib/views/home.dart b/lib/views/home.dart new file mode 100644 index 0000000..21b7938 --- /dev/null +++ b/lib/views/home.dart @@ -0,0 +1,49 @@ +import 'package:flutter/material.dart'; + +import 'package:app/views/portfolio.dart'; +import 'package:app/views/dividends.dart'; + +class HomeState extends State { + int _currentIndex = 0; + final List _children = [ + Portfolio(), + Dividends() + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Bezunca Investimentos'), + ), + body: _children[_currentIndex], + bottomNavigationBar: BottomNavigationBar( + onTap: onTabTapped, + currentIndex: _currentIndex, + items: [ + BottomNavigationBarItem( + icon: new Icon(Icons.account_balance_wallet), + title: new Text('Portfolio'), + ), + BottomNavigationBarItem( + icon: new Icon(Icons.attach_money), + title: new Text('Proventos'), + ) + ], + ), + ); + } + + void onTabTapped(int index) { + setState(() { + _currentIndex = index; + }); + } +} + +class Home extends StatefulWidget { + @override + State createState() { + return HomeState(); + } +} diff --git a/lib/login.dart b/lib/views/login.dart similarity index 79% rename from lib/login.dart rename to lib/views/login.dart index d407253..826717a 100644 --- a/lib/login.dart +++ b/lib/views/login.dart @@ -1,14 +1,9 @@ -import 'dart:convert'; +import 'package:app/utils/theme.dart'; -import 'package:app/CEICredentials.dart'; +import 'package:app/utils/CEICredentials.dart'; import 'package:flutter/material.dart'; class LoginState extends State { - - // Fonts - final _normalFont = const TextStyle(fontSize: 18.0); - - final _buttonFont = const TextStyle(fontSize: 18.0, color: Colors.white); final _cpf = TextEditingController(); final _password = TextEditingController(); @@ -27,22 +22,22 @@ class LoginState extends State { TextFormField( controller: _cpf, keyboardType: TextInputType.text, - style: _normalFont, - decoration: InputDecoration(labelText: "CPF", labelStyle: _normalFont) + style: normalFont, + decoration: InputDecoration(labelText: "CPF", labelStyle: normalFont) ), TextFormField( controller: _password, obscureText: true, keyboardType: TextInputType.text, - style: _normalFont, - decoration: InputDecoration(labelText: "Senha", labelStyle: _normalFont) + style: normalFont, + decoration: InputDecoration(labelText: "Senha", labelStyle: normalFont) ), Container( height: 40.0, margin: EdgeInsets.only(top: 30.0), child: RaisedButton( color: Colors.blue, - child: Text("LOGIN", style: _buttonFont), + child: Text("LOGIN", style: buttonFont), onPressed: () { _onClickLogin(context); }, ), ) diff --git a/lib/portfolio.dart b/lib/views/portfolio.dart similarity index 71% rename from lib/portfolio.dart rename to lib/views/portfolio.dart index fca9d8c..8abfbea 100644 --- a/lib/portfolio.dart +++ b/lib/views/portfolio.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'asset.dart'; +import 'package:app/utils/theme.dart'; +import '../models/asset.dart'; class PortfolioState extends State { final _portfolio = [ @@ -16,23 +17,9 @@ class PortfolioState extends State { Asset("IShare SP500CI", "IVVB11", 11597, "etf") ]; - // Fonts - final _biggerFont = - const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold); - final _normalFont = const TextStyle(fontSize: 18.0); - final _smallerFont = const TextStyle(fontSize: 14.0, color: Colors.grey); - @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("Bezunca Investimentos"), - actions: [ - IconButton(icon: Icon(Icons.search), onPressed: () => {}), - ], - ), - body: _buildPortfolio(), - ); + return _buildPortfolio(); } Widget _buildPortfolio() { @@ -50,16 +37,16 @@ class PortfolioState extends State { return ListTile( title: Text( asset.name, - style: _biggerFont, + style: biggerFont, ), subtitle: Text( asset.ticker, - style: _smallerFont, + style: smallerFont, ), leading: Icon(asset.icon), trailing: Text( asset.price, - style: _normalFont, + style: normalFont, )); } } diff --git a/lib/splashScreen.dart b/lib/views/splashScreen.dart similarity index 85% rename from lib/splashScreen.dart rename to lib/views/splashScreen.dart index 15901b8..6f8db7b 100644 --- a/lib/splashScreen.dart +++ b/lib/views/splashScreen.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import "appInitializer.dart"; +import "../utils/appInitializer.dart"; class SplashScreen extends StatelessWidget{ @override diff --git a/pubspec.lock b/pubspec.lock index 5b6bbc9..eee840c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.13" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" async: dependency: transitive description: @@ -22,20 +36,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.3" - clock: + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.12" + convert: dependency: transitive description: - name: clock + name: convert url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" - collection: + version: "2.1.1" + crypto: dependency: transitive description: - name: collection + name: crypto url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "2.1.4" cupertino_icons: dependency: "direct main" description: @@ -50,13 +71,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.5" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" file: dependency: transitive description: @@ -74,6 +88,13 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.12" intl: dependency: transitive description: @@ -101,7 +122,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.6.4" path_provider: dependency: "direct dev" description: @@ -130,6 +151,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" platform: dependency: transitive description: @@ -151,6 +179,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.13" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -197,7 +232,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.16" + version: "0.2.15" typed_data: dependency: transitive description: @@ -219,6 +254,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.0" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.6.1" sdks: dart: ">=2.7.0 <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0"