Skip to content

Commit 43c15fa

Browse files
committed
updated to version 1.0.1+10
1 parent 0677150 commit 43c15fa

19 files changed

+799
-884
lines changed

analysis_options.yaml

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include: package:flutter_lints/flutter.yaml
2-
31
analyzer:
42
language:
53
strict-raw-types: true
@@ -28,4 +26,63 @@ linter:
2826
- avoid_unused_constructor_parameters
2927
- await_only_futures
3028
- camel_case_types
31-
- cancel_subscriptions
29+
- cancel_subscriptions
30+
- constant_identifier_names
31+
- control_flow_in_finally
32+
- curly_braces_in_flow_control_structures
33+
- directives_ordering
34+
- empty_catches
35+
- empty_constructor_bodies
36+
- empty_statements
37+
- file_names
38+
- hash_and_equals
39+
- implementation_imports
40+
- iterable_contains_unrelated_type
41+
- library_names
42+
- library_prefixes
43+
- list_remove_unrelated_type
44+
- literal_only_boolean_expressions
45+
- no_duplicate_case_values
46+
- non_constant_identifier_names
47+
- null_closures
48+
- omit_local_variable_types
49+
- only_throw_errors
50+
- overridden_fields
51+
- package_api_docs
52+
- package_names
53+
- package_prefixed_library_names
54+
- prefer_adjacent_string_concatenation
55+
- prefer_conditional_assignment
56+
- prefer_const_constructors
57+
- prefer_contains
58+
- prefer_equal_for_default_values
59+
- prefer_final_fields
60+
- prefer_generic_function_type_aliases
61+
- prefer_initializing_formals
62+
- prefer_interpolation_to_compose_strings
63+
- prefer_iterable_whereType
64+
- prefer_is_empty
65+
- prefer_is_not_empty
66+
- prefer_null_aware_operators
67+
- prefer_typing_uninitialized_variables
68+
- recursive_getters
69+
- slash_for_doc_comments
70+
- test_types_in_equals
71+
- throw_in_finally
72+
- type_init_formals
73+
- unawaited_futures
74+
- unnecessary_brace_in_string_interps
75+
- unnecessary_const
76+
- unnecessary_getters_setters
77+
- unnecessary_lambdas
78+
- unnecessary_new
79+
- unnecessary_null_aware_assignments
80+
- unnecessary_null_in_if_null_operators
81+
- unnecessary_parenthesis
82+
- unnecessary_statements
83+
- unnecessary_this
84+
- unrelated_type_equality_checks
85+
- use_function_type_syntax_for_parameters
86+
- use_rethrow_when_possible
87+
- valid_regexps
88+
- void_checks

lib/db/hive_services.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract class HiveServices {
5454
return box.toMap() as Map<String, dynamic>;
5555
}
5656

57-
static Future<List<E>?> getAll<E>(String boxName) async {
57+
static Future<List<E>> getAll<E>(String boxName) async {
5858
AppUtility.log('getting all items from box [$boxName]');
5959
final box = await _openBox<E>(boxName);
6060
return box.values.toList();

lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'package:flutter/scheduler.dart';
33
import 'package:flutter/services.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
5-
import 'package:grocery_list_maker/app_bloc_observer.dart';
65
import 'package:grocery_list_maker/constants/app_themes.dart';
76
import 'package:grocery_list_maker/constants/colors.dart';
87
import 'package:grocery_list_maker/constants/strings.dart';
@@ -31,7 +30,7 @@ void main() async {
3130
Future<void> initPreAppServices() async {
3231
WidgetsFlutterBinding.ensureInitialized();
3332

34-
Bloc.observer = AppBlocObserver();
33+
// Bloc.observer = AppBlocObserver();
3534

3635
await Hive.initFlutter();
3736

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:bloc/bloc.dart';
2+
import 'package:equatable/equatable.dart';
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'app_update_cubit.g.dart';
6+
part 'app_update_state.dart';
7+
8+
class AppUpdateCubit extends Cubit<AppUpdateState> {
9+
AppUpdateCubit() : super(const AppUpdateState());
10+
}

lib/modules/app_update/cubit/app_update_cubit.g.dart

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
part of 'app_update_cubit.dart';
2+
3+
enum AppUpdateStatus { initial, loading, success, failure }
4+
5+
extension AppUpdateStatusX on AppUpdateStatus {
6+
bool get isInitial => this == AppUpdateStatus.initial;
7+
bool get isLoading => this == AppUpdateStatus.loading;
8+
bool get isSuccess => this == AppUpdateStatus.success;
9+
bool get isFailure => this == AppUpdateStatus.failure;
10+
}
11+
12+
@JsonSerializable()
13+
class AppUpdateState extends Equatable {
14+
const AppUpdateState({
15+
this.status = AppUpdateStatus.initial,
16+
String? errorMessage,
17+
}) : errorMessage = errorMessage ?? '';
18+
19+
factory AppUpdateState.fromJson(Map<String, dynamic> json) =>
20+
_$AppUpdateStateFromJson(json);
21+
22+
Map<String, dynamic> toJson() => _$AppUpdateStateToJson(this);
23+
24+
final AppUpdateStatus status;
25+
final String errorMessage;
26+
27+
AppUpdateState copyWith({
28+
AppUpdateStatus? status,
29+
String? errorMessage,
30+
}) {
31+
return AppUpdateState(
32+
status: status ?? this.status,
33+
errorMessage: errorMessage ?? this.errorMessage,
34+
);
35+
}
36+
37+
@override
38+
List<Object> get props => [status, errorMessage];
39+
}

lib/modules/grocery_item/cubit/grocery_item_cubit.dart

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ class GroceryItemCubit extends Cubit<GroceryItemState> {
2222
status: GroceryItemStatus.success,
2323
groceryItems: data,
2424
));
25-
} on Exception {
26-
emit(state.copyWith(status: GroceryItemStatus.failure));
25+
} catch (e) {
26+
emit(state.copyWith(
27+
status: GroceryItemStatus.failure,
28+
errorMessage: e.toString(),
29+
groceryItems: [...state.groceryItems],
30+
));
2731
}
2832
}
2933

@@ -36,19 +40,34 @@ class GroceryItemCubit extends Cubit<GroceryItemState> {
3640
emit(state.copyWith(status: GroceryItemStatus.loading));
3741

3842
try {
39-
final data = await _groceryRepository.addGroceryItem(
40-
listId: listId,
41-
title: title,
42-
description: description,
43-
quantity: quantity,
44-
);
43+
var isExists = await _groceryRepository.checkIfItemAlreadyExistsWithTitle(
44+
listId, title);
4545

46+
if (isExists) {
47+
emit(state.copyWith(
48+
status: GroceryItemStatus.failure,
49+
errorMessage: 'Grocery item with this title already exists',
50+
groceryItems: [...state.groceryItems],
51+
));
52+
} else {
53+
var item = await _groceryRepository.addGroceryItem(
54+
listId: listId,
55+
title: title,
56+
description: description,
57+
quantity: quantity,
58+
);
59+
60+
emit(state.copyWith(
61+
status: GroceryItemStatus.success,
62+
groceryItems: [...state.groceryItems, item],
63+
));
64+
}
65+
} catch (e) {
4666
emit(state.copyWith(
47-
status: GroceryItemStatus.success,
48-
groceryItems: [...state.groceryItems, data],
67+
status: GroceryItemStatus.failure,
68+
errorMessage: e.toString(),
69+
groceryItems: [...state.groceryItems],
4970
));
50-
} on Exception {
51-
emit(state.copyWith(status: GroceryItemStatus.failure));
5271
}
5372
}
5473

@@ -61,28 +80,51 @@ class GroceryItemCubit extends Cubit<GroceryItemState> {
6180
emit(state.copyWith(status: GroceryItemStatus.loading));
6281

6382
try {
64-
final data = await _groceryRepository.updateGroceryItem(
83+
var tempItem =
84+
state.groceryItems.firstWhere((element) => element.id == id);
85+
if (title != null && title.isNotEmpty && title != tempItem.title) {
86+
var isExists = await _groceryRepository
87+
.checkIfItemAlreadyExistsWithTitle(tempItem.listId, title);
88+
89+
if (isExists) {
90+
emit(state.copyWith(
91+
status: GroceryItemStatus.failure,
92+
errorMessage: 'Grocery item with this title already exists',
93+
groceryItems: [...state.groceryItems],
94+
));
95+
return;
96+
}
97+
}
98+
99+
var item = await _groceryRepository.updateGroceryItem(
65100
id,
66101
title: title,
67102
description: description,
68103
quantity: quantity,
69104
);
70105

71-
if (data == null) {
106+
if (item != null) {
107+
var temp = state.groceryItems;
108+
temp.removeWhere((element) => element.id == id);
109+
temp.add(item);
110+
111+
emit(state.copyWith(
112+
status: GroceryItemStatus.success,
113+
groceryItems: temp,
114+
));
115+
} else {
72116
emit(state.copyWith(
73117
status: GroceryItemStatus.failure,
74118
errorMessage: 'Grocery item not found',
119+
groceryItems: [...state.groceryItems],
75120
));
76-
return;
77121
}
78-
122+
} catch (e) {
79123
emit(state.copyWith(
80-
status: GroceryItemStatus.success,
81-
groceryItems:
82-
state.groceryItems.map((e) => e.id == data.id ? data : e).toList(),
124+
status: GroceryItemStatus.failure,
125+
errorMessage: e.toString(),
126+
groceryItems: [...state.groceryItems],
83127
));
84-
} on Exception {
85-
emit(state.copyWith(status: GroceryItemStatus.failure));
86128
}
87129
}
88130

@@ -92,13 +134,19 @@ class GroceryItemCubit extends Cubit<GroceryItemState> {
92134
try {
93135
await _groceryRepository.deleteGroceryItem(id, listId);
94136

137+
var temp = state.groceryItems;
138+
temp.removeWhere((element) => element.id == id);
139+
95140
emit(state.copyWith(
96141
status: GroceryItemStatus.success,
97-
groceryItems:
98-
state.groceryItems.where((element) => element.id != id).toList(),
142+
groceryItems: temp,
143+
));
144+
} catch (e) {
145+
emit(state.copyWith(
146+
status: GroceryItemStatus.failure,
147+
errorMessage: e.toString(),
148+
groceryItems: [...state.groceryItems],
99149
));
100-
} on Exception {
101-
emit(state.copyWith(status: GroceryItemStatus.failure));
102150
}
103151
}
104152
}

0 commit comments

Comments
 (0)