printer form, bluetooth
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart';
|
||||
|
||||
import '../../../../domain/printer/printer.dart';
|
||||
|
||||
part 'bluetooth_loader_event.dart';
|
||||
part 'bluetooth_loader_state.dart';
|
||||
part 'bluetooth_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class BluetoothLoaderBloc
|
||||
extends Bloc<BluetoothLoaderEvent, BluetoothLoaderState> {
|
||||
final IPrinterRepository _printerRepository;
|
||||
BluetoothLoaderBloc(this._printerRepository)
|
||||
: super(BluetoothLoaderState.initial()) {
|
||||
on<BluetoothLoaderEvent>(_onBluetoothLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onBluetoothLoaderEvent(
|
||||
BluetoothLoaderEvent event,
|
||||
Emitter<BluetoothLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(state.copyWith(isFetching: true, failureOption: none()));
|
||||
|
||||
final result = await _printerRepository.getPairedBluetoothDevices();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(
|
||||
state.copyWith(failureOption: optionOf(failure), isFetching: false),
|
||||
),
|
||||
(devices) => emit(
|
||||
state.copyWith(
|
||||
bluetoothDevices: devices,
|
||||
failureOption: none(),
|
||||
isFetching: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+379
@@ -0,0 +1,379 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'bluetooth_loader_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
|
||||
);
|
||||
|
||||
/// @nodoc
|
||||
mixin _$BluetoothLoaderEvent {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? fetched,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Fetched value) fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Fetched value)? fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Fetched value)? fetched,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $BluetoothLoaderEventCopyWith<$Res> {
|
||||
factory $BluetoothLoaderEventCopyWith(
|
||||
BluetoothLoaderEvent value,
|
||||
$Res Function(BluetoothLoaderEvent) then,
|
||||
) = _$BluetoothLoaderEventCopyWithImpl<$Res, BluetoothLoaderEvent>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$BluetoothLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends BluetoothLoaderEvent
|
||||
>
|
||||
implements $BluetoothLoaderEventCopyWith<$Res> {
|
||||
_$BluetoothLoaderEventCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of BluetoothLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$FetchedImplCopyWith<$Res> {
|
||||
factory _$$FetchedImplCopyWith(
|
||||
_$FetchedImpl value,
|
||||
$Res Function(_$FetchedImpl) then,
|
||||
) = __$$FetchedImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$FetchedImplCopyWithImpl<$Res>
|
||||
extends _$BluetoothLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
|
||||
implements _$$FetchedImplCopyWith<$Res> {
|
||||
__$$FetchedImplCopyWithImpl(
|
||||
_$FetchedImpl _value,
|
||||
$Res Function(_$FetchedImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of BluetoothLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$FetchedImpl implements _Fetched {
|
||||
const _$FetchedImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BluetoothLoaderEvent.fetched()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$FetchedImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({required TResult Function() fetched}) {
|
||||
return fetched();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? fetched}) {
|
||||
return fetched?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? fetched,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fetched != null) {
|
||||
return fetched();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Fetched value) fetched,
|
||||
}) {
|
||||
return fetched(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Fetched value)? fetched,
|
||||
}) {
|
||||
return fetched?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Fetched value)? fetched,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fetched != null) {
|
||||
return fetched(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Fetched implements BluetoothLoaderEvent {
|
||||
const factory _Fetched() = _$FetchedImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$BluetoothLoaderState {
|
||||
List<BluetoothInfo> get bluetoothDevices =>
|
||||
throw _privateConstructorUsedError;
|
||||
Option<PrinterFailure> get failureOption =>
|
||||
throw _privateConstructorUsedError;
|
||||
bool get isFetching => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of BluetoothLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$BluetoothLoaderStateCopyWith<BluetoothLoaderState> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $BluetoothLoaderStateCopyWith<$Res> {
|
||||
factory $BluetoothLoaderStateCopyWith(
|
||||
BluetoothLoaderState value,
|
||||
$Res Function(BluetoothLoaderState) then,
|
||||
) = _$BluetoothLoaderStateCopyWithImpl<$Res, BluetoothLoaderState>;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<BluetoothInfo> bluetoothDevices,
|
||||
Option<PrinterFailure> failureOption,
|
||||
bool isFetching,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$BluetoothLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends BluetoothLoaderState
|
||||
>
|
||||
implements $BluetoothLoaderStateCopyWith<$Res> {
|
||||
_$BluetoothLoaderStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of BluetoothLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? bluetoothDevices = null,
|
||||
Object? failureOption = null,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
bluetoothDevices: null == bluetoothDevices
|
||||
? _value.bluetoothDevices
|
||||
: bluetoothDevices // ignore: cast_nullable_to_non_nullable
|
||||
as List<BluetoothInfo>,
|
||||
failureOption: null == failureOption
|
||||
? _value.failureOption
|
||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<PrinterFailure>,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$BluetoothLoaderStateImplCopyWith<$Res>
|
||||
implements $BluetoothLoaderStateCopyWith<$Res> {
|
||||
factory _$$BluetoothLoaderStateImplCopyWith(
|
||||
_$BluetoothLoaderStateImpl value,
|
||||
$Res Function(_$BluetoothLoaderStateImpl) then,
|
||||
) = __$$BluetoothLoaderStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
List<BluetoothInfo> bluetoothDevices,
|
||||
Option<PrinterFailure> failureOption,
|
||||
bool isFetching,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$BluetoothLoaderStateImplCopyWithImpl<$Res>
|
||||
extends _$BluetoothLoaderStateCopyWithImpl<$Res, _$BluetoothLoaderStateImpl>
|
||||
implements _$$BluetoothLoaderStateImplCopyWith<$Res> {
|
||||
__$$BluetoothLoaderStateImplCopyWithImpl(
|
||||
_$BluetoothLoaderStateImpl _value,
|
||||
$Res Function(_$BluetoothLoaderStateImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of BluetoothLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? bluetoothDevices = null,
|
||||
Object? failureOption = null,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$BluetoothLoaderStateImpl(
|
||||
bluetoothDevices: null == bluetoothDevices
|
||||
? _value._bluetoothDevices
|
||||
: bluetoothDevices // ignore: cast_nullable_to_non_nullable
|
||||
as List<BluetoothInfo>,
|
||||
failureOption: null == failureOption
|
||||
? _value.failureOption
|
||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<PrinterFailure>,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$BluetoothLoaderStateImpl implements _BluetoothLoaderState {
|
||||
_$BluetoothLoaderStateImpl({
|
||||
required final List<BluetoothInfo> bluetoothDevices,
|
||||
required this.failureOption,
|
||||
this.isFetching = false,
|
||||
}) : _bluetoothDevices = bluetoothDevices;
|
||||
|
||||
final List<BluetoothInfo> _bluetoothDevices;
|
||||
@override
|
||||
List<BluetoothInfo> get bluetoothDevices {
|
||||
if (_bluetoothDevices is EqualUnmodifiableListView)
|
||||
return _bluetoothDevices;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_bluetoothDevices);
|
||||
}
|
||||
|
||||
@override
|
||||
final Option<PrinterFailure> failureOption;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isFetching;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BluetoothLoaderState(bluetoothDevices: $bluetoothDevices, failureOption: $failureOption, isFetching: $isFetching)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$BluetoothLoaderStateImpl &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other._bluetoothDevices,
|
||||
_bluetoothDevices,
|
||||
) &&
|
||||
(identical(other.failureOption, failureOption) ||
|
||||
other.failureOption == failureOption) &&
|
||||
(identical(other.isFetching, isFetching) ||
|
||||
other.isFetching == isFetching));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_bluetoothDevices),
|
||||
failureOption,
|
||||
isFetching,
|
||||
);
|
||||
|
||||
/// Create a copy of BluetoothLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$BluetoothLoaderStateImplCopyWith<_$BluetoothLoaderStateImpl>
|
||||
get copyWith =>
|
||||
__$$BluetoothLoaderStateImplCopyWithImpl<_$BluetoothLoaderStateImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
}
|
||||
|
||||
abstract class _BluetoothLoaderState implements BluetoothLoaderState {
|
||||
factory _BluetoothLoaderState({
|
||||
required final List<BluetoothInfo> bluetoothDevices,
|
||||
required final Option<PrinterFailure> failureOption,
|
||||
final bool isFetching,
|
||||
}) = _$BluetoothLoaderStateImpl;
|
||||
|
||||
@override
|
||||
List<BluetoothInfo> get bluetoothDevices;
|
||||
@override
|
||||
Option<PrinterFailure> get failureOption;
|
||||
@override
|
||||
bool get isFetching;
|
||||
|
||||
/// Create a copy of BluetoothLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$BluetoothLoaderStateImplCopyWith<_$BluetoothLoaderStateImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of 'bluetooth_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class BluetoothLoaderEvent with _$BluetoothLoaderEvent {
|
||||
const factory BluetoothLoaderEvent.fetched() = _Fetched;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
part of 'bluetooth_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class BluetoothLoaderState with _$BluetoothLoaderState {
|
||||
factory BluetoothLoaderState({
|
||||
required List<BluetoothInfo> bluetoothDevices,
|
||||
required Option<PrinterFailure> failureOption,
|
||||
@Default(false) bool isFetching,
|
||||
}) = _BluetoothLoaderState;
|
||||
|
||||
factory BluetoothLoaderState.initial() =>
|
||||
BluetoothLoaderState(bluetoothDevices: [], failureOption: none());
|
||||
}
|
||||
Reference in New Issue
Block a user