update position table, set selected table

This commit is contained in:
efrilm
2025-10-26 18:06:09 +07:00
parent 655902a659
commit 634b331716
15 changed files with 1195 additions and 61 deletions
@@ -0,0 +1,45 @@
import 'dart:ui';
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/table/table.dart';
part 'table_form_event.dart';
part 'table_form_state.dart';
part 'table_form_bloc.freezed.dart';
@injectable
class TableFormBloc extends Bloc<TableFormEvent, TableFormState> {
final ITableRepository _repository;
TableFormBloc(this._repository) : super(TableFormState.initial()) {
on<TableFormEvent>(_onTableFormEvent);
}
Future<void> _onTableFormEvent(
TableFormEvent event,
Emitter<TableFormState> emit,
) {
return event.map(
updated: (e) async {
Either<TableFailure, Table> failureOrTable;
emit(state.copyWith(isUpdating: true, failureOrTable: none()));
failureOrTable = await _repository.updatePosition(
id: e.id,
position: e.position,
);
emit(
state.copyWith(
failureOrTable: optionOf(failureOrTable),
isUpdating: false,
),
);
},
);
}
}
@@ -0,0 +1,410 @@
// 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 'table_form_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 _$TableFormEvent {
String get id => throw _privateConstructorUsedError;
Offset get position => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String id, Offset position) updated,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String id, Offset position)? updated,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String id, Offset position)? updated,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Updated value) updated,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Updated value)? updated,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Updated value)? updated,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$TableFormEventCopyWith<TableFormEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TableFormEventCopyWith<$Res> {
factory $TableFormEventCopyWith(
TableFormEvent value,
$Res Function(TableFormEvent) then,
) = _$TableFormEventCopyWithImpl<$Res, TableFormEvent>;
@useResult
$Res call({String id, Offset position});
}
/// @nodoc
class _$TableFormEventCopyWithImpl<$Res, $Val extends TableFormEvent>
implements $TableFormEventCopyWith<$Res> {
_$TableFormEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? id = null, Object? position = null}) {
return _then(
_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
position: null == position
? _value.position
: position // ignore: cast_nullable_to_non_nullable
as Offset,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$UpdatedImplCopyWith<$Res>
implements $TableFormEventCopyWith<$Res> {
factory _$$UpdatedImplCopyWith(
_$UpdatedImpl value,
$Res Function(_$UpdatedImpl) then,
) = __$$UpdatedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String id, Offset position});
}
/// @nodoc
class __$$UpdatedImplCopyWithImpl<$Res>
extends _$TableFormEventCopyWithImpl<$Res, _$UpdatedImpl>
implements _$$UpdatedImplCopyWith<$Res> {
__$$UpdatedImplCopyWithImpl(
_$UpdatedImpl _value,
$Res Function(_$UpdatedImpl) _then,
) : super(_value, _then);
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? id = null, Object? position = null}) {
return _then(
_$UpdatedImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
position: null == position
? _value.position
: position // ignore: cast_nullable_to_non_nullable
as Offset,
),
);
}
}
/// @nodoc
class _$UpdatedImpl implements _Updated {
const _$UpdatedImpl({required this.id, required this.position});
@override
final String id;
@override
final Offset position;
@override
String toString() {
return 'TableFormEvent.updated(id: $id, position: $position)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UpdatedImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.position, position) ||
other.position == position));
}
@override
int get hashCode => Object.hash(runtimeType, id, position);
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UpdatedImplCopyWith<_$UpdatedImpl> get copyWith =>
__$$UpdatedImplCopyWithImpl<_$UpdatedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String id, Offset position) updated,
}) {
return updated(id, position);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String id, Offset position)? updated,
}) {
return updated?.call(id, position);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String id, Offset position)? updated,
required TResult orElse(),
}) {
if (updated != null) {
return updated(id, position);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Updated value) updated,
}) {
return updated(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Updated value)? updated,
}) {
return updated?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Updated value)? updated,
required TResult orElse(),
}) {
if (updated != null) {
return updated(this);
}
return orElse();
}
}
abstract class _Updated implements TableFormEvent {
const factory _Updated({
required final String id,
required final Offset position,
}) = _$UpdatedImpl;
@override
String get id;
@override
Offset get position;
/// Create a copy of TableFormEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UpdatedImplCopyWith<_$UpdatedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$TableFormState {
Option<Either<TableFailure, Table>> get failureOrTable =>
throw _privateConstructorUsedError;
bool get isUpdating => throw _privateConstructorUsedError;
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$TableFormStateCopyWith<TableFormState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TableFormStateCopyWith<$Res> {
factory $TableFormStateCopyWith(
TableFormState value,
$Res Function(TableFormState) then,
) = _$TableFormStateCopyWithImpl<$Res, TableFormState>;
@useResult
$Res call({
Option<Either<TableFailure, Table>> failureOrTable,
bool isUpdating,
});
}
/// @nodoc
class _$TableFormStateCopyWithImpl<$Res, $Val extends TableFormState>
implements $TableFormStateCopyWith<$Res> {
_$TableFormStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? failureOrTable = null, Object? isUpdating = null}) {
return _then(
_value.copyWith(
failureOrTable: null == failureOrTable
? _value.failureOrTable
: failureOrTable // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Table>>,
isUpdating: null == isUpdating
? _value.isUpdating
: isUpdating // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$TableFormStateImplCopyWith<$Res>
implements $TableFormStateCopyWith<$Res> {
factory _$$TableFormStateImplCopyWith(
_$TableFormStateImpl value,
$Res Function(_$TableFormStateImpl) then,
) = __$$TableFormStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
Option<Either<TableFailure, Table>> failureOrTable,
bool isUpdating,
});
}
/// @nodoc
class __$$TableFormStateImplCopyWithImpl<$Res>
extends _$TableFormStateCopyWithImpl<$Res, _$TableFormStateImpl>
implements _$$TableFormStateImplCopyWith<$Res> {
__$$TableFormStateImplCopyWithImpl(
_$TableFormStateImpl _value,
$Res Function(_$TableFormStateImpl) _then,
) : super(_value, _then);
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? failureOrTable = null, Object? isUpdating = null}) {
return _then(
_$TableFormStateImpl(
failureOrTable: null == failureOrTable
? _value.failureOrTable
: failureOrTable // ignore: cast_nullable_to_non_nullable
as Option<Either<TableFailure, Table>>,
isUpdating: null == isUpdating
? _value.isUpdating
: isUpdating // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$TableFormStateImpl implements _TableFormState {
_$TableFormStateImpl({required this.failureOrTable, this.isUpdating = false});
@override
final Option<Either<TableFailure, Table>> failureOrTable;
@override
@JsonKey()
final bool isUpdating;
@override
String toString() {
return 'TableFormState(failureOrTable: $failureOrTable, isUpdating: $isUpdating)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TableFormStateImpl &&
(identical(other.failureOrTable, failureOrTable) ||
other.failureOrTable == failureOrTable) &&
(identical(other.isUpdating, isUpdating) ||
other.isUpdating == isUpdating));
}
@override
int get hashCode => Object.hash(runtimeType, failureOrTable, isUpdating);
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$TableFormStateImplCopyWith<_$TableFormStateImpl> get copyWith =>
__$$TableFormStateImplCopyWithImpl<_$TableFormStateImpl>(
this,
_$identity,
);
}
abstract class _TableFormState implements TableFormState {
factory _TableFormState({
required final Option<Either<TableFailure, Table>> failureOrTable,
final bool isUpdating,
}) = _$TableFormStateImpl;
@override
Option<Either<TableFailure, Table>> get failureOrTable;
@override
bool get isUpdating;
/// Create a copy of TableFormState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$TableFormStateImplCopyWith<_$TableFormStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'table_form_bloc.dart';
@freezed
class TableFormEvent with _$TableFormEvent {
const factory TableFormEvent.updated({
required String id,
required Offset position,
}) = _Updated;
}
@@ -0,0 +1,11 @@
part of 'table_form_bloc.dart';
@freezed
class TableFormState with _$TableFormState {
factory TableFormState({
required Option<Either<TableFailure, Table>> failureOrTable,
@Default(false) bool isUpdating,
}) = _TableFormState;
factory TableFormState.initial() => TableFormState(failureOrTable: none());
}