Skip to content

Commit

Permalink
fixed lints
Browse files Browse the repository at this point in the history
  • Loading branch information
i.khuzhakhmetov committed Oct 26, 2023
1 parent b673f30 commit 5c2038b
Show file tree
Hide file tree
Showing 46 changed files with 742 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install dependencies
run: flutter pub get

- name: Generate Freezed classes
- name: Generate classes
run: flutter pub run build_runner build --delete-conflicting-outputs

- name: Analyze project source
Expand Down
102 changes: 0 additions & 102 deletions lib/core/base/injectable_state.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/core/base/state_mixins.dart

This file was deleted.

11 changes: 7 additions & 4 deletions lib/core/di/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import 'package:e_shop_flutter/data/services/local_database/database.dart';
import 'package:e_shop_flutter/domain/repositories/items.repository.dart';
import 'package:e_shop_flutter/domain/repositories/purchases.repository.dart';
import 'package:e_shop_flutter/domain/usecases/add_new_purchase.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/change_app_theme_brighness.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/change_app_theme_brightness.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/delete_purchase.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/get_purchases.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/get_saved_brighness.usecase.dart';
import 'package:e_shop_flutter/presentation/add_purchase/logic/add_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/application/logic/application.cubit.dart';
import 'package:e_shop_flutter/domain/usecases/get_saved_brightness.usecase.dart';
import 'package:e_shop_flutter/presentation/cubits/add_purchase_cubit/add_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/application_cubit/application.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/delete_purchase_cubit/delete_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/get_all_purchases_cubit/get_all_purchases_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/get_items_by_purchase_cubit/get_Items_by_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/items_cubit/items_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/pick_date_cubit/pick_date_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/validation_cubit/validation_cubit.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down
6 changes: 6 additions & 0 deletions lib/core/di/src/cubits.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
part of '../di.dart';

void _registerCubits() {
locator.registerFactory(() => ItemsCubit());

locator.registerFactory(() => PickDateCubit());

locator.registerFactory(() => ValidationCubit());

locator.registerFactory(
() => DeletePurchaseCubit(deletePurchaseUsecase: locator()),
);
Expand Down
6 changes: 6 additions & 0 deletions lib/core/extensions/date.extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:intl/intl.dart';

extension DateExtension on DateTime {
String formattedDate({String format = 'dd MMMM yyyy'}) =>
DateFormat(format).format(this);
}
13 changes: 13 additions & 0 deletions lib/core/validations/text_validations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract class TextValidations {
static String? isNotEmpty(String? value) {
return value?.isNotEmpty == true ? null : 'Can not be empty';
}

static String? isCorrectPrice(String? value) {
final parsed = double.tryParse(value?.replaceAll(',', '.') ?? '');

return value?.isNotEmpty == true && parsed != null && parsed > 0
? null
: 'Incorrect price';
}
}
4 changes: 2 additions & 2 deletions lib/data/mappers/item_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ItemMapper extends Mapper<ItemView, ItemTableData> {
ItemView fromModel(ItemTableData model) => ItemView(
id: model.id ?? -1,
name: model.name,
count: model.count,
quantity: model.quantity,
price: model.price,
purchaseId: model.purchaseId ?? -1,
);
Expand All @@ -16,7 +16,7 @@ class ItemMapper extends Mapper<ItemView, ItemTableData> {
ItemTableData toModel(ItemView entity) => ItemTableData(
id: entity.id,
name: entity.name,
count: entity.count,
quantity: entity.quantity,
price: entity.price,
purchaseId: entity.purchaseId,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/item.table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:drift/drift.dart';
class ItemTable extends Table {
IntColumn get id => integer().nullable().autoIncrement()();
TextColumn get name => text()();
IntColumn get count => integer().withDefault(const Constant(1))();
RealColumn get quantity => real().withDefault(const Constant(1.0))();
RealColumn get price => real().withDefault(const Constant(0.0))();
IntColumn get purchaseId => integer().nullable().customConstraint(
'REFERENCES purchase(id) ON DELETE CASCADE',
Expand Down
18 changes: 9 additions & 9 deletions lib/domain/entities/item_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
class ItemView {
final int id;
final String name;
int count;
double quantity;
final double price;
final int purchaseId;

Expand All @@ -12,7 +12,7 @@ class ItemView {
ItemView({
required this.id,
required this.name,
required this.count,
required this.quantity,
required this.price,
required this.purchaseId,
});
Expand All @@ -21,7 +21,7 @@ class ItemView {
return {
'id': id,
'name': name,
'count': count,
'count': quantity,
'price': price,
'purchaseId': purchaseId,
};
Expand All @@ -31,7 +31,7 @@ class ItemView {
return ItemView(
id: map['id']?.toInt() ?? 0,
name: map['name'] ?? '',
count: map['count']?.toInt() ?? 0,
quantity: map['count']?.toInt() ?? 0,
price: map['price']?.toDouble() ?? 0.0,
purchaseId: map['purchaseId']?.toInt() ?? 0,
);
Expand All @@ -45,22 +45,22 @@ class ItemView {
ItemView copyWith({
int? id,
String? name,
int? count,
double? quantity,
double? price,
int? purchaseId,
}) {
return ItemView(
id: id ?? this.id,
name: name ?? this.name,
count: count ?? this.count,
quantity: quantity ?? this.quantity,
price: price ?? this.price,
purchaseId: purchaseId ?? this.purchaseId,
);
}

@override
String toString() {
return 'ItemView(id: $id, name: $name, count: $count, price: $price, purchaseId: $purchaseId)';
return 'ItemView(id: $id, name: $name, quantity: $quantity, price: $price, purchaseId: $purchaseId)';
}

@override
Expand All @@ -70,7 +70,7 @@ class ItemView {
return other is ItemView &&
other.id == id &&
other.name == name &&
other.count == count &&
other.quantity == quantity &&
other.price == price &&
other.purchaseId == purchaseId;
}
Expand All @@ -79,7 +79,7 @@ class ItemView {
int get hashCode {
return id.hashCode ^
name.hashCode ^
count.hashCode ^
quantity.hashCode ^
price.hashCode ^
purchaseId.hashCode;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/usecases/add_new_purchase.usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AddNewPurchaseUseCase {
PurchaseView(
id: -1,
name: purchaseName,
sum: items.map((e) => e.price * e.count).toList().sum(),
sum: items.map((e) => e.price * e.quantity).toList().sum(),
date: date,
),
);
Expand Down
9 changes: 6 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'package:e_shop_flutter/presentation/screens/application/application.dart';
import 'package:flutter/material.dart';

import 'core/di/di.dart';
import 'presentation/application/application.dart';

void main() {
//Initialize DI
setUp();

runApp(FutureBuilder(
runApp(
FutureBuilder(
future: locator.allReady(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Application();
} else {
return const CircularProgressIndicator();
}
}));
},
),
);
}
Loading

0 comments on commit 5c2038b

Please sign in to comment.