Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Conversation

MaxleyCv
Copy link
Collaborator

Created MR for lab 4

expect(find.text('1'), findsOneWidget);
});
}
// import 'package:flutter/material.dart';

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);

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;

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) {

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') {

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;

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;

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

builder: (context, cashInfo) {
List<Widget> newTransactions = [];
for (Transaction transaction in cashInfo.transactions){
newTransactions.add(_transactionCard(transaction));

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),
);
}
}
}

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

Copy link

@igor-leshkevych igor-leshkevych left a 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));

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 {

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"],

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;

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;

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);

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,

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(

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants