master #81
| @ -24,9 +24,8 @@ import 'package:wyatt_http_client/wyatt_http_client.dart'; | ||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class AlbumApiDataSourceImpl extends AlbumRemoteDataSource { | ||||
|   final MiddlewareClient _client; | ||||
| 
 | ||||
|   AlbumApiDataSourceImpl(this._client); | ||||
|   final MiddlewareClient _client; | ||||
| 
 | ||||
|   @override | ||||
|   Future<Album> getAlbum(int id) async { | ||||
|  | ||||
| @ -24,9 +24,8 @@ import 'package:wyatt_http_client/wyatt_http_client.dart'; | ||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class PhotoApiDataSourceImpl extends PhotoRemoteDataSource { | ||||
|   final MiddlewareClient _client; | ||||
| 
 | ||||
|   PhotoApiDataSourceImpl(this._client); | ||||
|   final MiddlewareClient _client; | ||||
| 
 | ||||
|   @override | ||||
|   Future<Photo> getPhoto(int id) async { | ||||
|  | ||||
| @ -24,15 +24,15 @@ import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class PhotoRepositoryImpl extends PhotoRepository { | ||||
|   final PhotoRemoteDataSource _photoRemoteDataSource; | ||||
|   final AlbumRemoteDataSource _albumRemoteDataSource; | ||||
|   final FavoriteLocalDataSource _favoriteLocalDataSource; | ||||
| 
 | ||||
|   PhotoRepositoryImpl( | ||||
|     this._photoRemoteDataSource, | ||||
|     this._albumRemoteDataSource, | ||||
|     this._favoriteLocalDataSource, | ||||
|   ); | ||||
|   final PhotoRemoteDataSource _photoRemoteDataSource; | ||||
|   final AlbumRemoteDataSource _albumRemoteDataSource; | ||||
|   final FavoriteLocalDataSource _favoriteLocalDataSource; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync( | ||||
|  | ||||
| @ -21,9 +21,9 @@ import 'package:architecture_example/domain/repositories/photo_repository.dart'; | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class AddPhotoToFavorites extends AsyncUseCase<Photo, List<Photo>> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   AddPhotoToFavorites(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>> execute(Photo? params) async { | ||||
|  | ||||
| @ -20,9 +20,9 @@ import 'package:architecture_example/domain/repositories/photo_repository.dart'; | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class CheckIfPhotoIsInFavorites extends AsyncUseCase<int, bool> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   CheckIfPhotoIsInFavorites(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<bool> execute(int? params) async => | ||||
|  | ||||
| @ -19,9 +19,9 @@ import 'package:architecture_example/domain/repositories/photo_repository.dart'; | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class DisplayFavorites extends AsyncUseCase<NoParam, List<Photo>> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   DisplayFavorites(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>> execute(void params) { | ||||
|  | ||||
| @ -21,9 +21,9 @@ import 'package:architecture_example/domain/repositories/photo_repository.dart'; | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class DisplayPhoto extends AsyncUseCase<int, Photo> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   DisplayPhoto(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<Photo> execute(int? params) { | ||||
|  | ||||
| @ -22,9 +22,9 @@ import 'package:architecture_example/domain/usecases/photos/params/query_paramet | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class OpenAlbum extends AsyncUseCase<QueryParameters, List<Photo>> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   OpenAlbum(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>> execute(QueryParameters? params) { | ||||
|  | ||||
| @ -15,9 +15,9 @@ | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| class QueryParameters { | ||||
| 
 | ||||
|   QueryParameters(this.start, this.limit, {this.albumId = -1}); | ||||
|   final int albumId; | ||||
|   final int? start; | ||||
|   final int? limit; | ||||
| 
 | ||||
|   QueryParameters(this.start, this.limit, {this.albumId = -1}); | ||||
| } | ||||
|  | ||||
| @ -21,9 +21,9 @@ import 'package:architecture_example/domain/repositories/photo_repository.dart'; | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class RemovePhotoFromFavorites extends AsyncUseCase<int, List<Photo>> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   RemovePhotoFromFavorites(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Photo>> execute(int? params) async { | ||||
|  | ||||
| @ -22,9 +22,9 @@ import 'package:architecture_example/domain/usecases/photos/params/query_paramet | ||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||
| 
 | ||||
| class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> { | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   RetrieveAllAlbums(this._photoRepository); | ||||
|   final PhotoRepository _photoRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Album>> execute(QueryParameters? params) { | ||||
|  | ||||
| @ -33,7 +33,6 @@ EventTransformer<E> throttleDroppable<E>(Duration duration) => | ||||
|     (events, mapper) => droppable<E>().call(events.throttle(duration), mapper); | ||||
| 
 | ||||
| class AlbumBloc extends Bloc<AlbumEvent, AlbumState> { | ||||
|   final RetrieveAllAlbums _retrieveAllAlbums; | ||||
| 
 | ||||
|   AlbumBloc(this._retrieveAllAlbums) : super(const AlbumState()) { | ||||
|     on<AlbumFetched>( | ||||
| @ -41,6 +40,7 @@ class AlbumBloc extends Bloc<AlbumEvent, AlbumState> { | ||||
|       transformer: throttleDroppable(throttleDuration), | ||||
|     ); | ||||
|   } | ||||
|   final RetrieveAllAlbums _retrieveAllAlbums; | ||||
| 
 | ||||
|   Future<void> _onAlbumFetched( | ||||
|     AlbumFetched event, | ||||
|  | ||||
| @ -26,19 +26,19 @@ abstract class PhotoDetailsState extends Equatable { | ||||
| class PhotoDetailsInitial extends PhotoDetailsState {} | ||||
| 
 | ||||
| class PhotoDetailsSuccess extends PhotoDetailsState { | ||||
|   final Photo photo; | ||||
|   final bool isFavorite; | ||||
| 
 | ||||
|   const PhotoDetailsSuccess(this.photo, {required this.isFavorite}); | ||||
|   final Photo photo; | ||||
|   final bool isFavorite; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object> get props => [photo, isFavorite]; | ||||
| } | ||||
| 
 | ||||
| class PhotoDetailsFailure extends PhotoDetailsState { | ||||
|   final String error; | ||||
| 
 | ||||
|   const PhotoDetailsFailure(this.error); | ||||
|   final String error; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object> get props => [error]; | ||||
|  | ||||
| @ -23,10 +23,10 @@ import 'package:flutter_bloc/flutter_bloc.dart'; | ||||
| part 'favorite_checker_state.dart'; | ||||
| 
 | ||||
| class FavoriteCheckerCubit extends Cubit<FavoriteCheckerState> { | ||||
|   final CheckIfPhotoIsInFavorites _checkIfPhotoIsInFavorites; | ||||
| 
 | ||||
|   FavoriteCheckerCubit(this._checkIfPhotoIsInFavorites) | ||||
|       : super(FavoriteCheckerInitial()); | ||||
|   final CheckIfPhotoIsInFavorites _checkIfPhotoIsInFavorites; | ||||
| 
 | ||||
|   FutureOr<void> checkIfPhotoIsInFavorites(int photoId) async { | ||||
|     final response = await _checkIfPhotoIsInFavorites.call(photoId); | ||||
|  | ||||
| @ -10,19 +10,19 @@ abstract class FavoriteCheckerState extends Equatable { | ||||
| class FavoriteCheckerInitial extends FavoriteCheckerState {} | ||||
| 
 | ||||
| class FavoriteCheckerSuccess extends FavoriteCheckerState { | ||||
|   final int photoId; | ||||
|   final bool isFavorite; | ||||
| 
 | ||||
|   const FavoriteCheckerSuccess(this.photoId, {required this.isFavorite}); | ||||
|   final int photoId; | ||||
|   final bool isFavorite; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object> get props => [photoId, isFavorite]; | ||||
| } | ||||
| 
 | ||||
| class FavoriteCheckerFailure extends FavoriteCheckerState { | ||||
|   final String error; | ||||
| 
 | ||||
|   const FavoriteCheckerFailure(this.error); | ||||
|   final String error; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object> get props => [error]; | ||||
|  | ||||
| @ -33,7 +33,6 @@ EventTransformer<E> throttleDroppable<E>(Duration duration) => | ||||
|     (events, mapper) => droppable<E>().call(events.throttle(duration), mapper); | ||||
| 
 | ||||
| class PhotoBloc extends Bloc<PhotoEvent, PhotoState> { | ||||
|   final OpenAlbum _openAlbum; | ||||
| 
 | ||||
|   PhotoBloc(this._openAlbum) : super(const PhotoState()) { | ||||
|     on<PhotoFetched>( | ||||
| @ -41,6 +40,7 @@ class PhotoBloc extends Bloc<PhotoEvent, PhotoState> { | ||||
|       transformer: throttleDroppable(throttleDuration), | ||||
|     ); | ||||
|   } | ||||
|   final OpenAlbum _openAlbum; | ||||
| 
 | ||||
|   Future<void> _onPhotoFetched( | ||||
|     PhotoFetched event, | ||||
|  | ||||
| @ -24,7 +24,7 @@ abstract class PhotoEvent extends Equatable { | ||||
| } | ||||
| 
 | ||||
| class PhotoFetched extends PhotoEvent { | ||||
|   final int albumId; | ||||
| 
 | ||||
|   const PhotoFetched(this.albumId); | ||||
|   final int albumId; | ||||
| } | ||||
|  | ||||
| @ -17,9 +17,9 @@ | ||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| abstract class AppException implements Exception { | ||||
|   final String? message; | ||||
| 
 | ||||
|   AppException([this.message]); | ||||
|   final String? message; | ||||
| 
 | ||||
|   @override | ||||
|   String toString() { | ||||
|  | ||||
| @ -20,6 +20,7 @@ part 'exceptions_firebase.dart'; | ||||
| 
 | ||||
| abstract class AuthenticationFailureInterface extends AppException | ||||
|     implements Exception { | ||||
| 
 | ||||
|   AuthenticationFailureInterface(this.code, this.msg); | ||||
|   AuthenticationFailureInterface.fromCode(this.code) | ||||
|       : msg = 'An unknown error occurred.'; | ||||
|  | ||||
| @ -20,8 +20,8 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class AuthenticationCacheDataSourceImpl<T extends Object> | ||||
|     extends AuthenticationCacheDataSource<T> { | ||||
|   AuthenticationCacheDataSourceImpl(); | ||||
| 
 | ||||
|   AuthenticationCacheDataSourceImpl(); | ||||
|   Account? _account; | ||||
|   T? _data; | ||||
| 
 | ||||
|  | ||||
| @ -21,11 +21,11 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; | ||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { | ||||
| 
 | ||||
|   AuthenticationMockDataSourceImpl({ | ||||
|     this.idToken = 'fake-id-token', | ||||
|     this.registeredAccounts, | ||||
|   }); | ||||
| 
 | ||||
|   Pair<Account, String>? _connectedMock; | ||||
|   Pair<Account, String>? _registeredMock; | ||||
|   DateTime _lastSignInTime = DateTime.now(); | ||||
|  | ||||
| @ -93,7 +93,6 @@ class AuthenticationRepositoryImpl<T extends Object> | ||||
|         ), | ||||
|       ); | ||||
|   } | ||||
| 
 | ||||
|   final AuthenticationCacheDataSource<T> _authenticationLocalDataSource; | ||||
|   final AuthenticationRemoteDataSource _authenticationRemoteDataSource; | ||||
| 
 | ||||
|  | ||||
| @ -26,6 +26,7 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| part 'authentication_state.dart'; | ||||
| 
 | ||||
| class AuthenticationCubit<Extra> extends Cubit<AuthenticationState<Extra>> { | ||||
| 
 | ||||
|   AuthenticationCubit({ | ||||
|     required AuthenticationRepository<Extra> authenticationRepository, | ||||
|   })  : _authenticationRepository = authenticationRepository, | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
| part of 'authentication_cubit.dart'; | ||||
| 
 | ||||
| class AuthenticationState<Extra> extends Equatable { | ||||
| 
 | ||||
|   const AuthenticationState.unauthenticated() | ||||
|       : this._(status: AuthenticationStatus.unauthenticated); | ||||
| 
 | ||||
|  | ||||
| @ -22,7 +22,6 @@ class SignInState extends FormDataState { | ||||
|     super.status = FormStatus.pure, | ||||
|     super.errorMessage, | ||||
|   }); | ||||
| 
 | ||||
|   FormInputValidator<String?, ValidationError> get email => | ||||
|       form.validatorOf(AuthFormField.email); | ||||
|   FormInputValidator<String?, ValidationError> get password => | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
| part of 'sign_up_cubit.dart'; | ||||
| 
 | ||||
| class SignUpState extends FormDataState { | ||||
| 
 | ||||
|   const SignUpState({ | ||||
|     required super.form, | ||||
|     super.status = FormStatus.pure, | ||||
|  | ||||
| @ -24,14 +24,14 @@ import 'package:wyatt_crud_bloc/src/domain/entities/query.dart'; | ||||
| 
 | ||||
| class CrudInMemoryDataSourceImpl<Model extends ObjectModel> | ||||
|     extends CrudDataSource<Model> { | ||||
| 
 | ||||
|   CrudInMemoryDataSourceImpl({required this.toMap, Map<String, Model>? data}) | ||||
|       : _data = data ?? {}; | ||||
|   final Map<String, Model> _data; | ||||
|   final StreamController<List<Model?>> _streamData = StreamController(); | ||||
| 
 | ||||
|   final Map<String, Object?> Function(Model) toMap; | ||||
| 
 | ||||
|   CrudInMemoryDataSourceImpl({required this.toMap, Map<String, Model>? data}) | ||||
|       : _data = data ?? {}; | ||||
| 
 | ||||
|   @override | ||||
|   Future<void> create(Model object, {String? id}) async { | ||||
|     _data[id ?? object.id ?? ''] = object; | ||||
|  | ||||
| @ -22,10 +22,6 @@ import 'package:wyatt_crud_bloc/src/domain/entities/query.dart'; | ||||
| 
 | ||||
| class CrudFirestoreDataSourceImpl<Model extends ObjectModel, Entity> | ||||
|     extends CrudDataSource<Model> { | ||||
|   final FirebaseFirestore _firestore; | ||||
| 
 | ||||
|   final Map<String, Object?> Function(Model, SetOptions?) _toFirestore; | ||||
|   late CollectionReference<Model> _collectionReference; | ||||
| 
 | ||||
|   CrudFirestoreDataSourceImpl( | ||||
|     String collection, { | ||||
| @ -44,6 +40,10 @@ class CrudFirestoreDataSourceImpl<Model extends ObjectModel, Entity> | ||||
|               toFirestore: toFirestore, | ||||
|             ); | ||||
|   } | ||||
|   final FirebaseFirestore _firestore; | ||||
| 
 | ||||
|   final Map<String, Object?> Function(Model, SetOptions?) _toFirestore; | ||||
|   late CollectionReference<Model> _collectionReference; | ||||
| 
 | ||||
|   @override | ||||
|   Future<void> create(Model object, {String? id}) { | ||||
|  | ||||
| @ -23,11 +23,11 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||
| 
 | ||||
| class CrudRepositoryImpl<Model extends ObjectModel> | ||||
|     extends CrudRepository<Model> { | ||||
|   final CrudDataSource<Model> _crudDataSource; | ||||
| 
 | ||||
|   CrudRepositoryImpl({ | ||||
|     required CrudDataSource<Model> crudDataSource, | ||||
|   }) : _crudDataSource = crudDataSource; | ||||
|   final CrudDataSource<Model> _crudDataSource; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<void> create(Model object, {String? id}) => | ||||
|  | ||||
| @ -25,22 +25,22 @@ abstract class QueryParser<Q> { | ||||
| abstract class QueryInterface extends Entity {} | ||||
| 
 | ||||
| class WhereQuery<Value> extends QueryInterface { | ||||
| 
 | ||||
|   WhereQuery(this.type, this.field, this.value); | ||||
|   final WhereQueryType type; | ||||
|   final String field; | ||||
|   final Value value; | ||||
| 
 | ||||
|   WhereQuery(this.type, this.field, this.value); | ||||
| } | ||||
| 
 | ||||
| class LimitQuery extends QueryInterface { | ||||
|   final int limit; | ||||
| 
 | ||||
|   LimitQuery(this.limit); | ||||
|   final int limit; | ||||
| } | ||||
| 
 | ||||
| class OrderByQuery extends QueryInterface { | ||||
|   final String field; | ||||
|   final bool ascending; | ||||
| 
 | ||||
|   OrderByQuery(this.field, {this.ascending = true}); | ||||
|   final String field; | ||||
|   final bool ascending; | ||||
| } | ||||
|  | ||||
| @ -21,9 +21,9 @@ import 'package:wyatt_crud_bloc/src/domain/entities/object_model.dart'; | ||||
| import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class Delete<Model extends ObjectModel> extends AsyncUseCase<String, void> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   Delete(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(String? params) { | ||||
|  | ||||
| @ -19,9 +19,9 @@ import 'package:wyatt_crud_bloc/src/domain/entities/object_model.dart'; | ||||
| import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class DeleteAll<Model extends ObjectModel> extends AsyncUseCase<void, void> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   DeleteAll(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<void> execute(void params) => _crudRepository.deleteAll(); | ||||
|  | ||||
| @ -21,9 +21,9 @@ import 'package:wyatt_crud_bloc/src/domain/entities/object_model.dart'; | ||||
| import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class Get<Model extends ObjectModel> extends AsyncUseCase<String, Model?> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   Get(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(String? params) { | ||||
|  | ||||
| @ -20,9 +20,9 @@ import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class GetAll<Model extends ObjectModel> | ||||
|     extends AsyncUseCase<void, List<Model?>> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   GetAll(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOrResult<List<Model?>> execute(void params) => _crudRepository.getAll(); | ||||
|  | ||||
| @ -23,9 +23,9 @@ import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class Query<Model extends ObjectModel> | ||||
|     extends AsyncUseCase<List<QueryInterface>, List<Model?>> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   Query(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(List<QueryInterface>? params) { | ||||
|  | ||||
| @ -23,9 +23,9 @@ import 'package:wyatt_crud_bloc/src/domain/usecases/params/update_parameters.dar | ||||
| 
 | ||||
| class Update<Model extends ObjectModel> | ||||
|     extends AsyncUseCase<UpdateParameters<Model>, void> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   Update(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(UpdateParameters<Model>? params) { | ||||
|  | ||||
| @ -22,9 +22,9 @@ import 'package:wyatt_crud_bloc/src/domain/repositories/crud_repository.dart'; | ||||
| 
 | ||||
| class UpdateAll<Model extends ObjectModel> | ||||
|     extends AsyncUseCase<Map<String, Object?>, void> { | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   UpdateAll(this._crudRepository); | ||||
|   final CrudRepository<Model> _crudRepository; | ||||
| 
 | ||||
|   @override | ||||
|   FutureOr<void> onStart(Map<String, Object?>? params) { | ||||
|  | ||||
| @ -35,6 +35,8 @@ import 'package:wyatt_crud_bloc/src/domain/usecases/update_all.dart'; | ||||
| part 'crud_state.dart'; | ||||
| 
 | ||||
| abstract class CrudCubit<Model extends ObjectModel> extends Cubit<CrudState> { | ||||
| 
 | ||||
|   CrudCubit() : super(CrudInitial()); | ||||
|   Create<Model>? get crudCreate; | ||||
|   DeleteAll<Model>? get crudDeleteAll; | ||||
|   Delete<Model>? get crudDelete; | ||||
| @ -44,8 +46,6 @@ abstract class CrudCubit<Model extends ObjectModel> extends Cubit<CrudState> { | ||||
|   UpdateAll<Model>? get crudUpdateAll; | ||||
|   Update<Model>? get crudUpdate; | ||||
| 
 | ||||
|   CrudCubit() : super(CrudInitial()); | ||||
| 
 | ||||
|   FutureOr<void> create(Model model) async { | ||||
|     if (crudCreate != null) { | ||||
|       final stateCopy = state; | ||||
|  | ||||
| @ -36,27 +36,27 @@ class CrudOkReturn extends CrudState { | ||||
| } | ||||
| 
 | ||||
| class CrudError extends CrudState { | ||||
|   final String? message; | ||||
| 
 | ||||
|   const CrudError(this.message); | ||||
|   final String? message; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object?> get props => [message]; | ||||
| } | ||||
| 
 | ||||
| class CrudLoaded<T> extends CrudSuccess { | ||||
|   final T? data; | ||||
| 
 | ||||
|   const CrudLoaded(this.data); | ||||
|   final T? data; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object?> get props => [data]; | ||||
| } | ||||
| 
 | ||||
| class CrudListLoaded<T> extends CrudSuccess { | ||||
|   final List<T?> data; | ||||
| 
 | ||||
|   const CrudListLoaded(this.data); | ||||
|   final List<T?> data; | ||||
| 
 | ||||
|   @override | ||||
|   List<Object> get props => [data]; | ||||
|  | ||||
| @ -26,15 +26,6 @@ import 'package:wyatt_form_bloc/src/domain/input_validators/form_input_validator | ||||
| 
 | ||||
| // ignore: must_be_immutable | ||||
| class WyattFormImpl extends WyattForm { | ||||
|   final List< | ||||
|       FormInput<dynamic, FormInputValidator<dynamic, ValidationError>, | ||||
|           dynamic>> _inputs; | ||||
|   final FormValidator _validator; | ||||
|   final String _name; | ||||
| 
 | ||||
|   late List< | ||||
|       FormInput<dynamic, FormInputValidator<dynamic, ValidationError>, | ||||
|           dynamic>> _inputsInitial; | ||||
| 
 | ||||
|   WyattFormImpl( | ||||
|     this._inputs, { | ||||
| @ -44,6 +35,15 @@ class WyattFormImpl extends WyattForm { | ||||
|         _validator = validationStrategy { | ||||
|     _inputsInitial = _inputs.map((input) => input.clone()).toList(); | ||||
|   } | ||||
|   final List< | ||||
|       FormInput<dynamic, FormInputValidator<dynamic, ValidationError>, | ||||
|           dynamic>> _inputs; | ||||
|   final FormValidator _validator; | ||||
|   final String _name; | ||||
| 
 | ||||
|   late List< | ||||
|       FormInput<dynamic, FormInputValidator<dynamic, ValidationError>, | ||||
|           dynamic>> _inputsInitial; | ||||
| 
 | ||||
|   @override | ||||
|   List< | ||||
|  | ||||
| @ -17,6 +17,12 @@ | ||||
| part of 'form_data_cubit.dart'; | ||||
| 
 | ||||
| abstract class FormDataState extends Equatable { | ||||
| 
 | ||||
|   const FormDataState({ | ||||
|     required this.form, | ||||
|     this.status = FormStatus.pure, | ||||
|     this.errorMessage, | ||||
|   }); | ||||
|   /// Global status of a form. | ||||
|   final FormStatus status; | ||||
| 
 | ||||
| @ -26,12 +32,6 @@ abstract class FormDataState extends Equatable { | ||||
|   /// Optional error message. | ||||
|   final String? errorMessage; | ||||
| 
 | ||||
|   const FormDataState({ | ||||
|     required this.form, | ||||
|     this.status = FormStatus.pure, | ||||
|     this.errorMessage, | ||||
|   }); | ||||
| 
 | ||||
|   @override | ||||
|   List<Object?> get props => [status, form, errorMessage]; | ||||
| } | ||||
|  | ||||
| @ -27,11 +27,11 @@ import 'package:wyatt_form_bloc/src/presentation/features/form_data/form_data_cu | ||||
| part 'form_data_state_impl.dart'; | ||||
| 
 | ||||
| abstract class FormDataCubitImpl extends FormDataCubit<FormDataStateImpl> { | ||||
|   final FormRepository _formRepository; | ||||
|   final String _formName; | ||||
| 
 | ||||
|   FormDataCubitImpl(this._formRepository, this._formName) | ||||
|       : super(FormDataStateImpl(form: _formRepository.accessForm(_formName))); | ||||
|   final FormRepository _formRepository; | ||||
|   final String _formName; | ||||
| 
 | ||||
|   @override | ||||
|   String get formName => _formName; | ||||
|  | ||||
| @ -115,7 +115,7 @@ Future<void> server() async { | ||||
|   final server = await HttpServer.bind(InternetAddress.anyIPv6, 8080); | ||||
|   var error = 0; | ||||
|   var token = 0; | ||||
|   await server.forEach((HttpRequest request) { | ||||
|   await server.forEach((request) { | ||||
|     print('[${request.method}] ${request.uri}'); | ||||
|     switch (request.uri.path) { | ||||
|       case '/test/basic-test': | ||||
| @ -196,7 +196,7 @@ Future<void> server() async { | ||||
| 
 | ||||
| Future<void> main() async { | ||||
|   unawaited(server()); | ||||
|   final base = 'localhost:8080'; | ||||
|   const base = 'localhost:8080'; | ||||
|   final uriPrefix = UriPrefixMiddleware( | ||||
|     protocol: Protocols.http, | ||||
|     authority: base, | ||||
|  | ||||
| @ -31,19 +31,15 @@ enum EmailVerificationAction { | ||||
|   resetPassword, | ||||
|   changeEmail; | ||||
| 
 | ||||
|   String toSnakeCase() { | ||||
|     return name.splitMapJoin( | ||||
|   String toSnakeCase() => name.splitMapJoin( | ||||
|       RegExp('[A-Z]'), | ||||
|       onMatch: (m) => '_${m[0]?.toLowerCase()}', | ||||
|       onNonMatch: (n) => n, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   factory EmailVerificationAction.fromString(String str) { | ||||
|     return EmailVerificationAction.values.firstWhere( | ||||
|       (EmailVerificationAction element) => element.toSnakeCase() == str, | ||||
|   factory EmailVerificationAction.fromString(String str) => EmailVerificationAction.values.firstWhere( | ||||
|       (element) => element.toSnakeCase() == str, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| class VerifyCode { | ||||
| @ -60,29 +56,23 @@ class VerifyCode { | ||||
|     String? email, | ||||
|     String? verificationCode, | ||||
|     EmailVerificationAction? action, | ||||
|   }) { | ||||
|     return VerifyCode( | ||||
|   }) => VerifyCode( | ||||
|       email: email ?? this.email, | ||||
|       verificationCode: verificationCode ?? this.verificationCode, | ||||
|       action: action ?? this.action, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return <String, dynamic>{ | ||||
|   Map<String, dynamic> toMap() => <String, dynamic>{ | ||||
|       'email': email, | ||||
|       'verification_code': verificationCode, | ||||
|       'action': action.toSnakeCase(), | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   factory VerifyCode.fromMap(Map<String, dynamic> map) { | ||||
|     return VerifyCode( | ||||
|   factory VerifyCode.fromMap(Map<String, dynamic> map) => VerifyCode( | ||||
|       email: map['email'] as String, | ||||
|       verificationCode: map['verification_code'] as String, | ||||
|       action: EmailVerificationAction.fromString(map['action'] as String), | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   String toJson() => json.encode(toMap()); | ||||
| 
 | ||||
| @ -105,26 +95,20 @@ class Account { | ||||
|   Account copyWith({ | ||||
|     String? email, | ||||
|     String? sessionId, | ||||
|   }) { | ||||
|     return Account( | ||||
|   }) => Account( | ||||
|       email: email ?? this.email, | ||||
|       sessionId: sessionId ?? this.sessionId, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return <String, dynamic>{ | ||||
|   Map<String, dynamic> toMap() => <String, dynamic>{ | ||||
|       'email': email, | ||||
|       'session_id': sessionId, | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   factory Account.fromMap(Map<String, dynamic> map) { | ||||
|     return Account( | ||||
|   factory Account.fromMap(Map<String, dynamic> map) => Account( | ||||
|       email: map['email'] as String, | ||||
|       sessionId: map['session_id'] != null ? map['session_id'] as String : null, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   String toJson() => json.encode(toMap()); | ||||
| 
 | ||||
| @ -146,26 +130,20 @@ class SignUp { | ||||
|   SignUp copyWith({ | ||||
|     String? sessionId, | ||||
|     String? password, | ||||
|   }) { | ||||
|     return SignUp( | ||||
|   }) => SignUp( | ||||
|       sessionId: sessionId ?? this.sessionId, | ||||
|       password: password ?? this.password, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return <String, dynamic>{ | ||||
|   Map<String, dynamic> toMap() => <String, dynamic>{ | ||||
|       'session_id': sessionId, | ||||
|       'password': password, | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   factory SignUp.fromMap(Map<String, dynamic> map) { | ||||
|     return SignUp( | ||||
|   factory SignUp.fromMap(Map<String, dynamic> map) => SignUp( | ||||
|       sessionId: map['session_id'] as String, | ||||
|       password: map['password'] as String, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   String toJson() => json.encode(toMap()); | ||||
| 
 | ||||
| @ -190,29 +168,23 @@ class TokenSuccess { | ||||
|     String? accessToken, | ||||
|     String? refreshToken, | ||||
|     Account? account, | ||||
|   }) { | ||||
|     return TokenSuccess( | ||||
|   }) => TokenSuccess( | ||||
|       accessToken: accessToken ?? this.accessToken, | ||||
|       refreshToken: refreshToken ?? this.refreshToken, | ||||
|       account: account ?? this.account, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return <String, dynamic>{ | ||||
|   Map<String, dynamic> toMap() => <String, dynamic>{ | ||||
|       'access_token': accessToken, | ||||
|       'refresh_token': refreshToken, | ||||
|       'account': account.toMap(), | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   factory TokenSuccess.fromMap(Map<String, dynamic> map) { | ||||
|     return TokenSuccess( | ||||
|   factory TokenSuccess.fromMap(Map<String, dynamic> map) => TokenSuccess( | ||||
|       accessToken: map['access_token'] as String, | ||||
|       refreshToken: map['refresh_token'] as String, | ||||
|       account: Account.fromMap(map['account'] as Map<String, dynamic>), | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   String toJson() => json.encode(toMap()); | ||||
| 
 | ||||
| @ -235,26 +207,20 @@ class Login { | ||||
|   Login copyWith({ | ||||
|     String? email, | ||||
|     String? password, | ||||
|   }) { | ||||
|     return Login( | ||||
|   }) => Login( | ||||
|       email: email ?? this.email, | ||||
|       password: password ?? this.password, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return <String, dynamic>{ | ||||
|   Map<String, dynamic> toMap() => <String, dynamic>{ | ||||
|       'email': email, | ||||
|       'password': password, | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   factory Login.fromMap(Map<String, dynamic> map) { | ||||
|     return Login( | ||||
|   factory Login.fromMap(Map<String, dynamic> map) => Login( | ||||
|       email: map['email'] as String, | ||||
|       password: map['password'] as String, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   String toJson() => json.encode(toMap()); | ||||
| 
 | ||||
|  | ||||
| @ -25,8 +25,6 @@ import 'package:wyatt_http_client/src/pipeline.dart'; | ||||
| import 'package:wyatt_http_client/src/utils/http_methods.dart'; | ||||
| 
 | ||||
| class MiddlewareClient extends BaseClient { | ||||
|   final Client inner; | ||||
|   final Pipeline pipeline; | ||||
| 
 | ||||
|   MiddlewareClient({ | ||||
|     Pipeline? pipeline, | ||||
| @ -35,6 +33,8 @@ class MiddlewareClient extends BaseClient { | ||||
|         inner = inner ?? Client() { | ||||
|     print('Using Pipeline:\n$pipeline'); | ||||
|   } | ||||
|   final Client inner; | ||||
|   final Pipeline pipeline; | ||||
| 
 | ||||
|   @override | ||||
|   Future<Response> head(Uri url, {Map<String, String>? headers}) => | ||||
| @ -81,9 +81,7 @@ class MiddlewareClient extends BaseClient { | ||||
|       _sendUnstreamed(HttpMethods.delete.method, url, headers, body, encoding); | ||||
| 
 | ||||
|   @override | ||||
|   Future<StreamedResponse> send(BaseRequest request) { | ||||
|     return inner.send(request); | ||||
|   } | ||||
|   Future<StreamedResponse> send(BaseRequest request) => inner.send(request); | ||||
| 
 | ||||
|   Future<Response> _sendUnstreamed( | ||||
|     String method, | ||||
|  | ||||
| @ -23,15 +23,15 @@ import 'package:wyatt_http_client/src/utils/authentication_methods.dart'; | ||||
| import 'package:wyatt_http_client/src/utils/header_keys.dart'; | ||||
| 
 | ||||
| class BasicAuthMiddleware with OnRequestMiddleware implements Middleware { | ||||
|   String? username; | ||||
|   String? password; | ||||
|   final String authenticationHeader; | ||||
| 
 | ||||
|   BasicAuthMiddleware({ | ||||
|     this.username, | ||||
|     this.password, | ||||
|     this.authenticationHeader = HeaderKeys.authorization, | ||||
|   }); | ||||
|   String? username; | ||||
|   String? password; | ||||
|   final String authenticationHeader; | ||||
| 
 | ||||
|   @override | ||||
|   String getName() => 'BasicAuth'; | ||||
|  | ||||
| @ -25,12 +25,6 @@ import 'package:wyatt_http_client/src/utils/http_status.dart'; | ||||
| class DigestAuthMiddleware | ||||
|     with OnRequestMiddleware, OnResponseMiddleware | ||||
|     implements Middleware { | ||||
|   final String username; | ||||
|   final String password; | ||||
|   final DigestAuth _digestAuth; | ||||
|   final String authenticationHeader; | ||||
|   final String wwwAuthenticateHeader; | ||||
|   final HttpStatus unauthorized; | ||||
| 
 | ||||
|   DigestAuthMiddleware({ | ||||
|     required this.username, | ||||
| @ -39,6 +33,12 @@ class DigestAuthMiddleware | ||||
|     this.wwwAuthenticateHeader = HeaderKeys.wwwAuthenticate, | ||||
|     this.unauthorized = HttpStatus.unauthorized, | ||||
|   }) : _digestAuth = DigestAuth(username, password); | ||||
|   final String username; | ||||
|   final String password; | ||||
|   final DigestAuth _digestAuth; | ||||
|   final String authenticationHeader; | ||||
|   final String wwwAuthenticateHeader; | ||||
|   final HttpStatus unauthorized; | ||||
| 
 | ||||
|   @override | ||||
|   String getName() => 'DigestAuth'; | ||||
|  | ||||
| @ -31,6 +31,17 @@ typedef TokenParser = String Function(Map<String, dynamic>); | ||||
| class RefreshTokenAuthMiddleware | ||||
|     with OnRequestMiddleware, OnResponseMiddleware | ||||
|     implements Middleware { | ||||
| 
 | ||||
|   RefreshTokenAuthMiddleware({ | ||||
|     required this.authorizationEndpoint, | ||||
|     required this.tokenEndpoint, | ||||
|     required this.accessTokenParser, | ||||
|     required this.refreshTokenParser, | ||||
|     this.authenticationHeader = HeaderKeys.authorization, | ||||
|     this.authenticationMethod = AuthenticationMethods.bearer, | ||||
|     this.unauthorized = HttpStatus.unauthorized, | ||||
|     this.maxAttempts = 8, | ||||
|   }); | ||||
|   final String authorizationEndpoint; | ||||
|   final String tokenEndpoint; | ||||
| 
 | ||||
| @ -44,17 +55,6 @@ class RefreshTokenAuthMiddleware | ||||
|   final HttpStatus unauthorized; | ||||
|   final int maxAttempts; | ||||
| 
 | ||||
|   RefreshTokenAuthMiddleware({ | ||||
|     required this.authorizationEndpoint, | ||||
|     required this.tokenEndpoint, | ||||
|     required this.accessTokenParser, | ||||
|     required this.refreshTokenParser, | ||||
|     this.authenticationHeader = HeaderKeys.authorization, | ||||
|     this.authenticationMethod = AuthenticationMethods.bearer, | ||||
|     this.unauthorized = HttpStatus.unauthorized, | ||||
|     this.maxAttempts = 8, | ||||
|   }); | ||||
| 
 | ||||
|   @override | ||||
|   String getName() => 'RefreshToken'; | ||||
| 
 | ||||
|  | ||||
| @ -20,11 +20,6 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart'; | ||||
| import 'package:wyatt_http_client/src/utils/convert.dart'; | ||||
| 
 | ||||
| class UnsafeAuthMiddleware with OnRequestMiddleware implements Middleware { | ||||
|   String? username; | ||||
|   String? password; | ||||
| 
 | ||||
|   final String usernameField; | ||||
|   final String passwordField; | ||||
| 
 | ||||
|   UnsafeAuthMiddleware({ | ||||
|     this.username, | ||||
| @ -32,6 +27,11 @@ class UnsafeAuthMiddleware with OnRequestMiddleware implements Middleware { | ||||
|     this.usernameField = 'username', | ||||
|     this.passwordField = 'password', | ||||
|   }); | ||||
|   String? username; | ||||
|   String? password; | ||||
| 
 | ||||
|   final String usernameField; | ||||
|   final String passwordField; | ||||
| 
 | ||||
|   @override | ||||
|   String getName() => 'UnsafeAuth'; | ||||
|  | ||||
| @ -20,13 +20,13 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart'; | ||||
| import 'package:wyatt_http_client/src/utils/protocols.dart'; | ||||
| 
 | ||||
| class UriPrefixMiddleware with OnRequestMiddleware implements Middleware { | ||||
|   final Protocols protocol; | ||||
|   final String? authority; | ||||
| 
 | ||||
|   UriPrefixMiddleware({ | ||||
|     required this.protocol, | ||||
|     required this.authority, | ||||
|   }); | ||||
|   final Protocols protocol; | ||||
|   final String? authority; | ||||
| 
 | ||||
|   @override | ||||
|   String getName() => 'UriPrefix'; | ||||
|  | ||||
| @ -44,8 +44,7 @@ class MiddlewareContext { | ||||
|     MiddlewareRequest? lastRequest, | ||||
|     MiddlewareResponse? originalResponse, | ||||
|     MiddlewareResponse? lastResponse, | ||||
|   }) { | ||||
|     return MiddlewareContext( | ||||
|   }) => MiddlewareContext( | ||||
|       pipeline: pipeline ?? this.pipeline, | ||||
|       client: client ?? this.client, | ||||
|       originalRequest: originalRequest ?? this.originalRequest, | ||||
| @ -53,10 +52,7 @@ class MiddlewareContext { | ||||
|       originalResponse: originalResponse ?? this.originalResponse, | ||||
|       lastResponse: lastResponse ?? this.lastResponse, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   String toString() { | ||||
|     return 'MiddlewareContext(pipeline: $pipeline, client: $client, originalRequest: $originalRequest, lastRequest: $lastRequest, originalResponse: $originalResponse, lastResponse: $lastResponse)'; | ||||
|   } | ||||
|   String toString() => 'MiddlewareContext(pipeline: $pipeline, client: $client, originalRequest: $originalRequest, lastRequest: $lastRequest, originalResponse: $originalResponse, lastResponse: $lastResponse)'; | ||||
| } | ||||
|  | ||||
| @ -42,22 +42,21 @@ class MiddlewareRequest { | ||||
| 
 | ||||
|   MiddlewareRequest copyWith({ | ||||
|     UnfreezedRequest? unfreezedRequest, | ||||
|   }) { | ||||
|     return MiddlewareRequest( | ||||
|       unfreezedRequest: unfreezedRequest ?? this.unfreezedRequest, | ||||
|     ); | ||||
|   } | ||||
|   }) => | ||||
|       MiddlewareRequest( | ||||
|         unfreezedRequest: unfreezedRequest ?? this.unfreezedRequest, | ||||
|       ); | ||||
| 
 | ||||
|   void modifyRequest(UnfreezedRequest unfreezedRequest) { | ||||
|     String? _body; | ||||
|     String? body; | ||||
|     if (unfreezedRequest.body != null) { | ||||
|       final body = unfreezedRequest.body; | ||||
|       var body = unfreezedRequest.body; | ||||
|       if (body is String) { | ||||
|         _body = body; | ||||
|         body = body; | ||||
|       } else if (body is List) { | ||||
|         _body = String.fromCharCodes(body.cast<int>()); | ||||
|         body = String.fromCharCodes(body.cast<int>()); | ||||
|       } else if (body is Map) { | ||||
|         _body = Convert.mapToQuery(body.cast<String, String>()); | ||||
|         body = Convert.mapToQuery(body.cast<String, String>()); | ||||
|       } | ||||
|     } | ||||
|     _httpRequest = RequestUtils.copyRequestWith( | ||||
| @ -65,7 +64,7 @@ class MiddlewareRequest { | ||||
|       method: unfreezedRequest.method, | ||||
|       url: unfreezedRequest.url, | ||||
|       headers: unfreezedRequest.headers, | ||||
|       body: _body, | ||||
|       body: body, | ||||
|     ) as Request; | ||||
|     if (unfreezedRequest.encoding != null) { | ||||
|       _httpRequest.encoding = unfreezedRequest.encoding!; | ||||
|  | ||||
| @ -40,11 +40,9 @@ class MiddlewareResponse { | ||||
| 
 | ||||
|   MiddlewareResponse copyWith({ | ||||
|     BaseResponse? httpResponse, | ||||
|   }) { | ||||
|     return MiddlewareResponse( | ||||
|   }) => MiddlewareResponse( | ||||
|       httpResponse: httpResponse ?? this.httpResponse, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   String toString() => | ||||
|  | ||||
| @ -17,11 +17,6 @@ | ||||
| import 'dart:convert'; | ||||
| 
 | ||||
| class UnfreezedRequest { | ||||
|   final String method; | ||||
|   final Uri url; | ||||
|   final Map<String, String>? headers; | ||||
|   final Object? body; | ||||
|   final Encoding? encoding; | ||||
| 
 | ||||
|   UnfreezedRequest({ | ||||
|     required this.method, | ||||
| @ -30,6 +25,11 @@ class UnfreezedRequest { | ||||
|     this.body, | ||||
|     this.encoding, | ||||
|   }); | ||||
|   final String method; | ||||
|   final Uri url; | ||||
|   final Map<String, String>? headers; | ||||
|   final Object? body; | ||||
|   final Encoding? encoding; | ||||
| 
 | ||||
|   UnfreezedRequest copyWith({ | ||||
|     String? method, | ||||
| @ -37,19 +37,15 @@ class UnfreezedRequest { | ||||
|     Map<String, String>? headers, | ||||
|     Object? body, | ||||
|     Encoding? encoding, | ||||
|   }) { | ||||
|     return UnfreezedRequest( | ||||
|   }) => UnfreezedRequest( | ||||
|       method: method ?? this.method, | ||||
|       url: url ?? this.url, | ||||
|       headers: headers ?? this.headers, | ||||
|       body: body ?? this.body, | ||||
|       encoding: encoding ?? this.encoding, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   String toString() { | ||||
|     return 'UnfreezedRequest(method: $method, url: $url, headers: ' | ||||
|   String toString() => 'UnfreezedRequest(method: $method, url: $url, headers: ' | ||||
|         '$headers, body: $body, encoding: $encoding)'; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -20,13 +20,13 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart'; | ||||
| import 'package:wyatt_http_client/src/models/middleware_response.dart'; | ||||
| 
 | ||||
| class Pipeline { | ||||
|   final List<Middleware> _middlewares; | ||||
| 
 | ||||
|   int get length => _middlewares.length; | ||||
| 
 | ||||
|   Pipeline() : _middlewares = <Middleware>[]; | ||||
|   Pipeline.fromIterable(Iterable<Middleware> middlewares) | ||||
|       : _middlewares = middlewares.toList(); | ||||
|   final List<Middleware> _middlewares; | ||||
| 
 | ||||
|   int get length => _middlewares.length; | ||||
| 
 | ||||
|   /// Add a [Middleware] to this [Pipeline] | ||||
|   Pipeline addMiddleware(Middleware middleware) { | ||||
|  | ||||
| @ -21,7 +21,7 @@ class Convert { | ||||
|     final buffer = StringBuffer(); | ||||
|     for (final int part in bytes) { | ||||
|       if (part & 0xff != part) { | ||||
|         throw FormatException('Non-byte integer detected'); | ||||
|         throw const FormatException('Non-byte integer detected'); | ||||
|       } | ||||
|       buffer.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); | ||||
|     } | ||||
|  | ||||
| @ -21,8 +21,8 @@ import 'package:crypto/crypto.dart'; | ||||
| class Crypto { | ||||
|   /// Hash a string using MD5 | ||||
|   static String md5Hash(String data) { | ||||
|     final content = Utf8Encoder().convert(data); | ||||
|     final md5Crypto = md5; | ||||
|     final content = const Utf8Encoder().convert(data); | ||||
|     const md5Crypto = md5; | ||||
|     final digest = md5Crypto.convert(content).toString(); | ||||
|     return digest; | ||||
|   } | ||||
|  | ||||
| @ -24,9 +24,9 @@ abstract class Delay { | ||||
|       return Duration.zero; | ||||
|     } | ||||
|     final rand = Random(); | ||||
|     final Duration delayFactor = const Duration(milliseconds: 200); | ||||
|     final double randomizationFactor = 0.25; | ||||
|     final Duration maxDelay = const Duration(seconds: 30); | ||||
|     const Duration delayFactor = Duration(milliseconds: 200); | ||||
|     const double randomizationFactor = 0.25; | ||||
|     const Duration maxDelay = Duration(seconds: 30); | ||||
| 
 | ||||
|     final rf = randomizationFactor * (rand.nextDouble() * 2 - 1) + 1; | ||||
|     final exp = min(attempt, 31); // prevent overflows. | ||||
|  | ||||
| @ -19,7 +19,9 @@ import 'dart:math'; | ||||
| import 'package:wyatt_http_client/src/utils/convert.dart'; | ||||
| import 'package:wyatt_http_client/src/utils/crypto.dart'; | ||||
| 
 | ||||
| class DigestAuth { | ||||
| class DigestAuth { // request counter | ||||
| 
 | ||||
|   DigestAuth(this.username, this.password); | ||||
|   String username; | ||||
|   String password; | ||||
| 
 | ||||
| @ -30,9 +32,7 @@ class DigestAuth { | ||||
|   String? _nonce; | ||||
|   String? _opaque; | ||||
| 
 | ||||
|   int _nc = 0; // request counter | ||||
| 
 | ||||
|   DigestAuth(this.username, this.password); | ||||
|   int _nc = 0; | ||||
| 
 | ||||
|   /// Splits WWW-Authenticate header into a map. | ||||
|   Map<String, String>? splitWWWAuthenticateHeader(String header) { | ||||
| @ -61,9 +61,7 @@ class DigestAuth { | ||||
|     return Convert.toHex(values); | ||||
|   } | ||||
| 
 | ||||
|   String _formatNonceCount(int nc) { | ||||
|     return nc.toRadixString(16).padLeft(8, '0'); | ||||
|   } | ||||
|   String _formatNonceCount(int nc) => nc.toRadixString(16).padLeft(8, '0'); | ||||
| 
 | ||||
|   String _computeHA1( | ||||
|     String realm, | ||||
| @ -148,7 +146,7 @@ class DigestAuth { | ||||
|   } | ||||
| 
 | ||||
|   String getAuthString(String method, Uri url) { | ||||
|     final _cnonce = _computeNonce(); | ||||
|     final cnonce = _computeNonce(); | ||||
|     _nc += 1; | ||||
|     // if url has query parameters, append query to path | ||||
|     final path = url.hasQuery ? '${url.path}?${url.query}' : url.path; | ||||
| @ -162,7 +160,7 @@ class DigestAuth { | ||||
|       _qop, | ||||
|       _opaque, | ||||
|       _realm!, | ||||
|       _cnonce, | ||||
|       cnonce, | ||||
|       _nonce, | ||||
|       _nc, | ||||
|       username, | ||||
| @ -192,7 +190,5 @@ class DigestAuth { | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   bool isReady() { | ||||
|     return _nonce != null && (_nc == 0 || _qop != null); | ||||
|   } | ||||
|   bool isReady() => _nonce != null && (_nc == 0 || _qop != null); | ||||
| } | ||||
|  | ||||
| @ -95,29 +95,17 @@ enum HttpStatus { | ||||
|     return false; | ||||
|   } | ||||
| 
 | ||||
|   bool isInfo() { | ||||
|     return statusCode >= 100 && statusCode < 200;  | ||||
|   } | ||||
|   bool isInfo() => statusCode >= 100 && statusCode < 200; | ||||
| 
 | ||||
|   bool isSuccess() { | ||||
|     return statusCode >= 200 && statusCode < 300;  | ||||
|   } | ||||
|   bool isSuccess() => statusCode >= 200 && statusCode < 300; | ||||
| 
 | ||||
|   bool isRedirection() { | ||||
|     return statusCode >= 300 && statusCode < 400;  | ||||
|   } | ||||
|   bool isRedirection() => statusCode >= 300 && statusCode < 400; | ||||
| 
 | ||||
|   bool isClientError() { | ||||
|     return statusCode >= 400 && statusCode < 500;  | ||||
|   } | ||||
|   bool isClientError() => statusCode >= 400 && statusCode < 500; | ||||
| 
 | ||||
|   bool isServerError() { | ||||
|     return statusCode >= 500 && statusCode < 600;  | ||||
|   } | ||||
|   bool isServerError() => statusCode >= 500 && statusCode < 600; | ||||
| 
 | ||||
|   factory HttpStatus.from(int status) { | ||||
|     return HttpStatus.values | ||||
|   factory HttpStatus.from(int status) => HttpStatus.values | ||||
|         .firstWhere((element) => element.statusCode == status); | ||||
|   } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -15,9 +15,9 @@ | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| class AppError { | ||||
|   final String message; | ||||
| 
 | ||||
|   const AppError(this.message); | ||||
|   final String message; | ||||
| 
 | ||||
|   @override | ||||
|   // ignore: no_runtimetype_tostring | ||||
|  | ||||
| @ -28,8 +28,8 @@ mixin _Left<LeftType, RightType> on _EitherBase<LeftType, RightType> {} | ||||
| mixin _Right<LeftType, RightType> on _EitherBase<LeftType, RightType> {} | ||||
| 
 | ||||
| class _EitherBaseException implements Exception { | ||||
|   final String message; | ||||
|   const _EitherBaseException(this.message); | ||||
|   final String message; | ||||
| 
 | ||||
|   @override | ||||
|   String toString() => '_EitherException: $message'; | ||||
|  | ||||
| @ -172,10 +172,10 @@ abstract class Option<T> extends _EitherBase<T, void> { | ||||
| } | ||||
| 
 | ||||
| class Value<T> extends Option<T> with _Left<T, void> { | ||||
|   final T value; | ||||
| 
 | ||||
|   /// {@macro ok} | ||||
|   const Value(this.value) : super._(); | ||||
|   final T value; | ||||
| 
 | ||||
|   @override | ||||
|   _EitherBase<U, void> _and<U>(_EitherBase<U, void> res) => res as Option<U>; | ||||
|  | ||||
| @ -203,10 +203,10 @@ abstract class Result<T, E> extends _EitherBase<T, E> { | ||||
| /// {@macro result} | ||||
| /// {@endtemplate} | ||||
| class Ok<T, E> extends Result<T, E> with _Left<T, E> { | ||||
|   final T value; | ||||
| 
 | ||||
|   /// {@macro ok} | ||||
|   const Ok(this.value) : super._(); | ||||
|   final T value; | ||||
| 
 | ||||
|   @override | ||||
|   U _fold<U>(U Function(T left) fnL, U Function(E right) fnR) => fnL(value); | ||||
| @ -268,10 +268,10 @@ class Ok<T, E> extends Result<T, E> with _Left<T, E> { | ||||
| /// {@macro result} | ||||
| /// {@endtemplate} | ||||
| class Err<T, E> extends Result<T, E> with _Right<T, E> { | ||||
|   final E error; | ||||
| 
 | ||||
|   /// {@macro err} | ||||
|   const Err(this.error) : super._(); | ||||
|   final E error; | ||||
| 
 | ||||
|   @override | ||||
|   U _fold<U>(U Function(T left) fnL, U Function(E right) fnR) => fnR(error); | ||||
|  | ||||
| @ -22,11 +22,11 @@ extension PairExtension<T> on Pair<T, T> { | ||||
| /// [Pair] is a simple object which contains pair of two values. | ||||
| /// {@endtemplate} | ||||
| class Pair<L, R> { | ||||
|   final L? left; | ||||
|   final R? right; | ||||
| 
 | ||||
|   /// {@macro pair} | ||||
|   const Pair(this.left, this.right); | ||||
|   final L? left; | ||||
|   final R? right; | ||||
| 
 | ||||
|   @override | ||||
|   String toString() => '($left, $right)'; | ||||
|  | ||||
| @ -19,13 +19,13 @@ import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; | ||||
| import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart'; | ||||
| 
 | ||||
| class AppBarLayout extends Layout { | ||||
|   final String title; | ||||
|   final Widget body; | ||||
|   const AppBarLayout({ | ||||
|     required this.title, | ||||
|     required this.body, | ||||
|     super.key, | ||||
|   }); | ||||
|   final String title; | ||||
|   final Widget body; | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Scaffold( | ||||
|  | ||||
| @ -3,14 +3,14 @@ import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; | ||||
| import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart'; | ||||
| 
 | ||||
| class BottomNavigationBarLayout extends Layout { | ||||
|   final Widget body; | ||||
|   final int currentIndex; | ||||
| 
 | ||||
|   const BottomNavigationBarLayout({ | ||||
|     required this.currentIndex, | ||||
|     required this.body, | ||||
|     super.key, | ||||
|   }); | ||||
|   final Widget body; | ||||
|   final int currentIndex; | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Scaffold( | ||||
|         body: body, | ||||
|  | ||||
| @ -19,9 +19,6 @@ import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; | ||||
| import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart'; | ||||
| 
 | ||||
| class FrameLayout extends Layout { | ||||
|   final String title; | ||||
|   final Widget body; | ||||
|   final int currentIndex; | ||||
| 
 | ||||
|   const FrameLayout({ | ||||
|     required this.title, | ||||
| @ -29,6 +26,9 @@ class FrameLayout extends Layout { | ||||
|     required this.currentIndex, | ||||
|     super.key, | ||||
|   }); | ||||
|   final String title; | ||||
|   final Widget body; | ||||
|   final int currentIndex; | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Scaffold( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user