Skip to content

Commit 6bdf725

Browse files
committed
wip nnbd
1 parent 1db90f4 commit 6bdf725

25 files changed

+159
-171
lines changed

lib/data/exception/local_data_source_exception.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
class LocalDataSourceException implements Exception {
22
final String message;
33
final Object error;
4+
final StackTrace stackTrace;
45

5-
const LocalDataSourceException(this.message, this.error);
6+
const LocalDataSourceException(this.message, this.error, this.stackTrace);
67

78
@override
89
String toString() =>

lib/data/local/shared_pref_util.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ class SharedPrefUtil implements LocalDataSource {
1515
@override
1616
Future<void> removeUserAndToken() =>
1717
_rxPrefs.remove(_kUserTokenKey).onError<Object>((e, s) =>
18-
throw LocalDataSourceException('Cannot delete user and token', e));
18+
throw LocalDataSourceException('Cannot delete user and token', e, s));
1919

2020
@override
2121
Future<void> saveUserAndToken(UserAndTokenEntity userAndToken) {
2222
return _rxPrefs
2323
.write<UserAndTokenEntity>(_kUserTokenKey, userAndToken, _toString)
2424
.onError<Object>((e, s) =>
25-
throw LocalDataSourceException('Cannot save user and token', e));
25+
throw LocalDataSourceException('Cannot save user and token', e, s));
2626
}
2727

2828
@override
2929
Future<UserAndTokenEntity?> get userAndToken => _rxPrefs
3030
.read<UserAndTokenEntity>(_kUserTokenKey, _toEntity)
3131
.onError<Object>((e, s) =>
32-
throw LocalDataSourceException('Cannot read user and token', e));
32+
throw LocalDataSourceException('Cannot read user and token', e, s));
3333

3434
@override
3535
Stream<UserAndTokenEntity?> get userAndToken$ => _rxPrefs
3636
.observe<UserAndTokenEntity>(_kUserTokenKey, _toEntity)
37-
.onErrorReturnWith((e) =>
38-
throw LocalDataSourceException('Cannot read user and token', e));
37+
.onErrorReturnWith((e, s) =>
38+
throw LocalDataSourceException('Cannot read user and token', e, s));
3939

4040
static UserAndTokenEntity? _toEntity(dynamic jsonString) => jsonString == null
4141
? null

lib/data/remote/response/token_response.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ abstract class TokenResponse
2020
factory TokenResponse.fromJson(Map<String, dynamic> json) =>
2121
serializers.deserializeWith<TokenResponse>(serializer, json)!;
2222

23-
Map<String, dynamic> toJson() => serializers.serializeWith(serializer, this) as Map<String, dynamic>;
23+
Map<String, dynamic> toJson() =>
24+
serializers.serializeWith(serializer, this) as Map<String, dynamic>;
2425
}

lib/data/user_repository_imp.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class UserRepositoryImpl implements UserRepository {
194194
///
195195
/// Convert error to [Failure]
196196
///
197-
static Failure<T> _errorToResult<T extends Object>(Object e) {
197+
static Failure<T> _errorToResult<T extends Object>(Object e, StackTrace s) {
198198
if (e is RemoteDataSourceException) {
199199
return Failure.of(message: e.message, error: e);
200200
}

lib/domain/repositories/user_repository.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:io';
22

3-
import 'package:meta/meta.dart';
43
import 'package:node_auth/domain/models/auth_state.dart';
54
import 'package:node_auth/utils/result.dart';
65

lib/domain/usecases/change_password_use_case.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:node_auth/domain/repositories/user_repository.dart';
22
import 'package:node_auth/utils/result.dart';
3-
import 'package:meta/meta.dart';
43

54
class ChangePasswordUseCase {
65
final UserRepository _userRepository;

lib/domain/usecases/login_use_case.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:meta/meta.dart';
21
import 'package:node_auth/domain/repositories/user_repository.dart';
32
import 'package:node_auth/utils/result.dart';
43

lib/domain/usecases/register_use_case.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:meta/meta.dart';
21
import 'package:node_auth/domain/repositories/user_repository.dart';
32
import 'package:node_auth/utils/result.dart';
43

lib/domain/usecases/reset_password_use_case.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:node_auth/domain/repositories/user_repository.dart';
22
import 'package:node_auth/utils/result.dart';
3-
import 'package:meta/meta.dart';
43

54
class ResetPasswordUseCase {
65
final UserRepository _userRepository;

lib/pages/home/change_password/change_password_bloc.dart

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'dart:async';
22

33
import 'package:disposebag/disposebag.dart';
4+
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
45
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
5-
import 'package:meta/meta.dart';
66
import 'package:node_auth/domain/usecases/change_password_use_case.dart';
77
import 'package:node_auth/pages/home/change_password/change_password.dart';
88
import 'package:node_auth/utils/result.dart';
@@ -25,9 +25,9 @@ class ChangePasswordBloc extends DisposeCallbackBaseBloc {
2525
final Function1<String, void> newPasswordChanged;
2626

2727
/// Output stream
28-
final Stream<ChangePasswordState> changePasswordState$;
29-
final Stream<String> passwordError$;
30-
final Stream<String> newPasswordError$;
28+
final DistinctValueStream<ChangePasswordState> changePasswordState$;
29+
final Stream<String?> passwordError$;
30+
final Stream<String?> newPasswordError$;
3131

3232
ChangePasswordBloc._({
3333
required this.changePassword,
@@ -40,8 +40,6 @@ class ChangePasswordBloc extends DisposeCallbackBaseBloc {
4040
}) : super(dispose);
4141

4242
factory ChangePasswordBloc(final ChangePasswordUseCase changePassword) {
43-
assert(ChangePasswordUseCase != null);
44-
4543
/// Controllers
4644
final passwordS = PublishSubject<String>();
4745
final newPasswordS = PublishSubject<String>();
@@ -71,7 +69,7 @@ class ChangePasswordBloc extends DisposeCallbackBaseBloc {
7169
.where((isValid) => isValid)
7270
.withLatestFrom(both$, (_, Tuple2<String, String> both) => both)
7371
.exhaustMap((both) => _performChangePassword(changePassword, both))
74-
.share();
72+
.publishValueDistinct(ChangePasswordState((b) => b..isLoading = false));
7573

7674
final passwordError$ = both$
7775
.map((tuple) {
@@ -134,22 +132,19 @@ class ChangePasswordBloc extends DisposeCallbackBaseBloc {
134132
) {
135133
print('[DEBUG] change password both=$both');
136134

137-
ChangePasswordState resultToState(result) {
135+
ChangePasswordState resultToState(Result<void> result) {
138136
print('[DEBUG] change password result=$result');
139137

140-
if (result is Success) {
141-
return ChangePasswordState((b) => b
138+
return result.fold(
139+
(value) => ChangePasswordState((b) => b
142140
..isLoading = false
143141
..error = null
144-
..message = 'Change password successfully!');
145-
}
146-
if (result is Failure) {
147-
return ChangePasswordState((b) => b
142+
..message = 'Change password successfully!'),
143+
(error, message) => ChangePasswordState((b) => b
148144
..isLoading = false
149-
..error = result.error
150-
..message = 'Error when change password: ${result.message}');
151-
}
152-
return null;
145+
..error = error
146+
..message = 'Error when change password: ${message}'),
147+
);
153148
}
154149

155150
return changePassword(password: both.item1, newPassword: both.item2)

0 commit comments

Comments
 (0)