-
Notifications
You must be signed in to change notification settings - Fork 0
Lab4 dev #9
base: main
Are you sure you want to change the base?
Conversation
LAB4: finalize state
expect(find.text('1'), findsOneWidget); | ||
}); | ||
} | ||
// import 'package:flutter/material.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of leaving a comment, it's better to either remove file completely, or leave test empty
lib/states.dart
Outdated
|
||
@immutable | ||
class CashState { | ||
static var startValues = CashState(10000, 0, 0, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
class CashState { | ||
static var startValues = CashState(10000, 0, 0, 100); | ||
double cash; | ||
double cashbackProducts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all values should be final
|
||
CashState cashReducer(CashState previousState, dynamic action) { | ||
double newCash = action.cash; | ||
if (action is MakeTransaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have more than 2 branches, use switch + action.runtimeType
instead of if
+ is
double taxiCashbackPercents = 0.03; | ||
double elseCashbackPercents = 0.03; | ||
|
||
if (action.typeOfTransaction == 'product') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by Redux philosophy, its better to use separate actions for all of that cases (prouct, taxi, etc.) because you have different logic for each of them
double newCash = action.cash; | ||
if (action is MakeTransaction) { | ||
double diff = previousState.cash - newCash; | ||
double productCashbackPercents = 0.03; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be some constant, and ideally out of this method
return CashState(newCash, previousState.cashbackProducts, | ||
previousState.cashbackTaxi, previousState.cashbackElse); | ||
} else { | ||
return previousState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last branch can be written without else, just
if (...) {
...
} else if (...) {
...
}
return previousState;
enum Action { MakeTransaction, MakeBankSaving } | ||
|
||
class MakeTransaction { | ||
double cash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
lib/HomePage/home_page.dart
Outdated
builder: (context, cashInfo) { | ||
List<Widget> newTransactions = []; | ||
for (Transaction transaction in cashInfo.transactions){ | ||
newTransactions.add(_transactionCard(transaction)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use [].map
instead
@@ -47,4 +47,4 @@ class _MyHomePageState extends State<MyHomePage> { | |||
body: HomePage(context), | |||
); | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont forget to leave empty lines at the end of the file
import 'package:monobank_app/monobank_icons.dart'; | ||
|
||
class Transaction { | ||
String time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaxleyCv @Ari100telll @max4nik your code is a bit "chaotic", but app works, and you've used redux which is also a plus. Good job.
10/10 everyone
), | ||
return StoreConnector<CashState, dynamic>( | ||
converter: (store) { | ||
return (newCash, jar_amount,jar_first_transaction,jar_name) => store.dispatch(MakeBankSaving(newCash, jar_amount,jar_first_transaction,jar_name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
@@ -109,3 +228,13 @@ class ScreeNavigationBarBackground extends StatelessWidget { | |||
); | |||
} | |||
} | |||
|
|||
// class ScreeNavigationBarBackground extends StatelessWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't leave commented blocks of code
value: 0.7, | ||
// value: 0.7, | ||
value: | ||
jarInfo["current_amount"] / jarInfo["total_amount"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid using dynamic maps, use statically typed objects instead
@@ -9,6 +9,9 @@ class MakeTransaction { | |||
|
|||
class MakeBankSaving { | |||
double cash; | |||
int amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
} | ||
} else if (action is MakeBankSaving) { | ||
double newCash = previousState.cash - action.firstTransacrion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
lib/states.dart
Outdated
{"total_amount": 9000, "current_amount": 5000, "name": "На гараж"}, | ||
{"total_amount": 9000, "current_amount": 3000, "name": "На гараж"}, | ||
{"total_amount": 9000, "current_amount": 6000, "name": "На гараж"}, | ||
], 5000+200+6000+5000+3000+6000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5000+200+6000+5000+3000+6000
isn't good: if you change any of the elements above, you'll have to change this line, too
{"total_amount": 9000, "current_amount": 3000, "name": "На гараж"}, | ||
{"total_amount": 9000, "current_amount": 6000, "name": "На гараж"}, | ||
], | ||
5000 + 200 + 6000 + 5000 + 3000 + 6000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
summing things using hardcode here is not good: if any of elements changes -> you'll have to update this line, too
if (action.typeOfTransaction == 'product') { | ||
double newProductCashback = | ||
previousState.cashbackProducts + diff * productCashbackPercents; | ||
return CashState( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid having long reducers. for each branch (= action type) it's better to have a separate method, and reducer should just call this method
Created MR for lab 4