mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2025-01-05 09:27:22 +03:00
refactor
This commit is contained in:
parent
454d36410c
commit
75073c149b
@ -47,7 +47,8 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
final viewNotifier = ref.read(nfcViewNotifier.notifier);
|
final viewNotifier = ref.read(nfcViewNotifier.notifier);
|
||||||
|
|
||||||
ref.listen(androidNfcActivityProvider, (previous, current) {
|
ref.listen(androidNfcActivityProvider, (previous, current) {
|
||||||
final notifier = ref.read(nfcEventCommandNotifier.notifier);
|
processingViewTimeout?.cancel();
|
||||||
|
final notifier = ref.read(nfcEventNotifier.notifier);
|
||||||
|
|
||||||
if (!explicitAction) {
|
if (!explicitAction) {
|
||||||
// setup properties for ad-hoc action
|
// setup properties for ad-hoc action
|
||||||
@ -57,21 +58,18 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
switch (current) {
|
switch (current) {
|
||||||
case NfcActivity.processingStarted:
|
case NfcActivity.processingStarted:
|
||||||
final timeout = explicitAction ? 300 : 500;
|
final timeout = explicitAction ? 300 : 500;
|
||||||
processingViewTimeout?.cancel();
|
|
||||||
processingViewTimeout = Timer(Duration(milliseconds: timeout), () {
|
processingViewTimeout = Timer(Duration(milliseconds: timeout), () {
|
||||||
notifier.sendCommand(showScanning());
|
notifier.send(showHoldStill());
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case NfcActivity.processingFinished:
|
case NfcActivity.processingFinished:
|
||||||
processingViewTimeout?.cancel();
|
notifier.send(showDone());
|
||||||
notifier.sendCommand(showDone());
|
notifier
|
||||||
notifier.sendCommand(hideNfcView(const Duration(milliseconds: 400)));
|
.send(const NfcHideViewEvent(delay: Duration(milliseconds: 400)));
|
||||||
|
|
||||||
explicitAction = false; // next action might not be explicit
|
explicitAction = false; // next action might not be explicit
|
||||||
break;
|
break;
|
||||||
case NfcActivity.processingInterrupted:
|
case NfcActivity.processingInterrupted:
|
||||||
processingViewTimeout?.cancel();
|
notifier.send(showFailed());
|
||||||
notifier.sendCommand(showFailed());
|
|
||||||
break;
|
break;
|
||||||
case NfcActivity.notActive:
|
case NfcActivity.notActive:
|
||||||
_log.debug('Received not handled notActive');
|
_log.debug('Received not handled notActive');
|
||||||
@ -82,11 +80,11 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_channel.setMethodCallHandler((call) async {
|
_channel.setMethodCallHandler((call) async {
|
||||||
final notifier = ref.read(nfcEventCommandNotifier.notifier);
|
final notifier = ref.read(nfcEventNotifier.notifier);
|
||||||
switch (call.method) {
|
switch (call.method) {
|
||||||
case 'show':
|
case 'show':
|
||||||
explicitAction = true;
|
explicitAction = true;
|
||||||
notifier.sendCommand(showTapYourYubiKey());
|
notifier.send(showTapYourYubiKey());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'close':
|
case 'close':
|
||||||
@ -103,34 +101,36 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NfcEventCommand showTapYourYubiKey() {
|
NfcEvent showTapYourYubiKey() {
|
||||||
ref
|
ref
|
||||||
.read(nfcViewNotifier.notifier)
|
.read(nfcViewNotifier.notifier)
|
||||||
.setDialogProperties(showCloseButton: true);
|
.setDialogProperties(showCloseButton: true);
|
||||||
return setNfcView(NfcContentWidget(
|
return NfcSetViewEvent(
|
||||||
|
child: NfcContentWidget(
|
||||||
title: l10n.s_nfc_ready_to_scan,
|
title: l10n.s_nfc_ready_to_scan,
|
||||||
subtitle: l10n.s_nfc_tap_your_yubikey,
|
subtitle: l10n.s_nfc_tap_your_yubikey,
|
||||||
icon: const NfcIconProgressBar(false),
|
icon: const NfcIconProgressBar(false),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
NfcEventCommand showScanning() {
|
NfcEvent showHoldStill() {
|
||||||
ref
|
ref
|
||||||
.read(nfcViewNotifier.notifier)
|
.read(nfcViewNotifier.notifier)
|
||||||
.setDialogProperties(showCloseButton: false);
|
.setDialogProperties(showCloseButton: false);
|
||||||
return setNfcView(NfcContentWidget(
|
return NfcSetViewEvent(
|
||||||
|
child: NfcContentWidget(
|
||||||
title: l10n.s_nfc_ready_to_scan,
|
title: l10n.s_nfc_ready_to_scan,
|
||||||
subtitle: l10n.s_nfc_hold_still,
|
subtitle: l10n.s_nfc_hold_still,
|
||||||
icon: const NfcIconProgressBar(true),
|
icon: const NfcIconProgressBar(true),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
NfcEventCommand showDone() {
|
NfcEvent showDone() {
|
||||||
ref
|
ref
|
||||||
.read(nfcViewNotifier.notifier)
|
.read(nfcViewNotifier.notifier)
|
||||||
.setDialogProperties(showCloseButton: true);
|
.setDialogProperties(showCloseButton: true);
|
||||||
return setNfcView(
|
return NfcSetViewEvent(
|
||||||
NfcContentWidget(
|
child: NfcContentWidget(
|
||||||
title: l10n.s_nfc_ready_to_scan,
|
title: l10n.s_nfc_ready_to_scan,
|
||||||
subtitle: l10n.s_done,
|
subtitle: l10n.s_done,
|
||||||
icon: const NfcIconSuccess(),
|
icon: const NfcIconSuccess(),
|
||||||
@ -138,12 +138,12 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
showIfHidden: false);
|
showIfHidden: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
NfcEventCommand showFailed() {
|
NfcEvent showFailed() {
|
||||||
ref
|
ref
|
||||||
.read(nfcViewNotifier.notifier)
|
.read(nfcViewNotifier.notifier)
|
||||||
.setDialogProperties(showCloseButton: true);
|
.setDialogProperties(showCloseButton: true);
|
||||||
return setNfcView(
|
return NfcSetViewEvent(
|
||||||
NfcContentWidget(
|
child: NfcContentWidget(
|
||||||
title: l10n.s_nfc_ready_to_scan,
|
title: l10n.s_nfc_ready_to_scan,
|
||||||
subtitle: l10n.l_nfc_failed_to_scan,
|
subtitle: l10n.l_nfc_failed_to_scan,
|
||||||
icon: const NfcIconFailure(),
|
icon: const NfcIconFailure(),
|
||||||
@ -152,7 +152,7 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void closeDialog() {
|
void closeDialog() {
|
||||||
ref.read(nfcEventCommandNotifier.notifier).sendCommand(hideNfcView());
|
ref.read(nfcEventNotifier.notifier).send(const NfcHideViewEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancelDialog() async {
|
void cancelDialog() async {
|
||||||
@ -166,7 +166,7 @@ class _DialogProvider extends Notifier<int> {
|
|||||||
Timer.periodic(
|
Timer.periodic(
|
||||||
const Duration(milliseconds: 200),
|
const Duration(milliseconds: 200),
|
||||||
(timer) {
|
(timer) {
|
||||||
if (!ref.read(nfcViewNotifier.select((s) => s.isShowing))) {
|
if (ref.read(nfcViewNotifier.select((s) => !s.visible))) {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,9 @@ class NfcEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class NfcHideViewEvent extends NfcEvent {
|
class NfcHideViewEvent extends NfcEvent {
|
||||||
final Duration hideAfter;
|
final Duration delay;
|
||||||
|
|
||||||
const NfcHideViewEvent({required this.hideAfter});
|
const NfcHideViewEvent({this.delay = Duration.zero});
|
||||||
}
|
|
||||||
|
|
||||||
class NfcCancelEvent extends NfcEvent {
|
|
||||||
const NfcCancelEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NfcSetViewEvent extends NfcEvent {
|
class NfcSetViewEvent extends NfcEvent {
|
||||||
@ -43,22 +39,8 @@ class NfcSetViewEvent extends NfcEvent {
|
|||||||
@freezed
|
@freezed
|
||||||
class NfcView with _$NfcView {
|
class NfcView with _$NfcView {
|
||||||
factory NfcView({
|
factory NfcView({
|
||||||
required bool isShowing,
|
|
||||||
required Widget child,
|
required Widget child,
|
||||||
bool? showCloseButton,
|
@Default(false) bool visible,
|
||||||
|
@Default(false) bool hasCloseButton,
|
||||||
}) = _NfcView;
|
}) = _NfcView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
|
||||||
class NfcEventCommand with _$NfcEventCommand {
|
|
||||||
factory NfcEventCommand({
|
|
||||||
@Default(NfcEvent()) NfcEvent event,
|
|
||||||
}) = _NfcEventCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
NfcEventCommand hideNfcView([Duration hideAfter = Duration.zero]) =>
|
|
||||||
NfcEventCommand(event: NfcHideViewEvent(hideAfter: hideAfter));
|
|
||||||
|
|
||||||
NfcEventCommand setNfcView(Widget child, {bool showIfHidden = true}) =>
|
|
||||||
NfcEventCommand(
|
|
||||||
event: NfcSetViewEvent(child: child, showIfHidden: showIfHidden));
|
|
||||||
|
@ -16,9 +16,9 @@ final _privateConstructorUsedError = UnsupportedError(
|
|||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
mixin _$NfcView {
|
mixin _$NfcView {
|
||||||
bool get isShowing => throw _privateConstructorUsedError;
|
|
||||||
Widget get child => throw _privateConstructorUsedError;
|
Widget get child => throw _privateConstructorUsedError;
|
||||||
bool? get showCloseButton => throw _privateConstructorUsedError;
|
bool get visible => throw _privateConstructorUsedError;
|
||||||
|
bool get hasCloseButton => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
/// Create a copy of NfcView
|
/// Create a copy of NfcView
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@ -31,7 +31,7 @@ abstract class $NfcViewCopyWith<$Res> {
|
|||||||
factory $NfcViewCopyWith(NfcView value, $Res Function(NfcView) then) =
|
factory $NfcViewCopyWith(NfcView value, $Res Function(NfcView) then) =
|
||||||
_$NfcViewCopyWithImpl<$Res, NfcView>;
|
_$NfcViewCopyWithImpl<$Res, NfcView>;
|
||||||
@useResult
|
@useResult
|
||||||
$Res call({bool isShowing, Widget child, bool? showCloseButton});
|
$Res call({Widget child, bool visible, bool hasCloseButton});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -49,23 +49,23 @@ class _$NfcViewCopyWithImpl<$Res, $Val extends NfcView>
|
|||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
@override
|
@override
|
||||||
$Res call({
|
$Res call({
|
||||||
Object? isShowing = null,
|
|
||||||
Object? child = null,
|
Object? child = null,
|
||||||
Object? showCloseButton = freezed,
|
Object? visible = null,
|
||||||
|
Object? hasCloseButton = null,
|
||||||
}) {
|
}) {
|
||||||
return _then(_value.copyWith(
|
return _then(_value.copyWith(
|
||||||
isShowing: null == isShowing
|
|
||||||
? _value.isShowing
|
|
||||||
: isShowing // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
child: null == child
|
child: null == child
|
||||||
? _value.child
|
? _value.child
|
||||||
: child // ignore: cast_nullable_to_non_nullable
|
: child // ignore: cast_nullable_to_non_nullable
|
||||||
as Widget,
|
as Widget,
|
||||||
showCloseButton: freezed == showCloseButton
|
visible: null == visible
|
||||||
? _value.showCloseButton
|
? _value.visible
|
||||||
: showCloseButton // ignore: cast_nullable_to_non_nullable
|
: visible // ignore: cast_nullable_to_non_nullable
|
||||||
as bool?,
|
as bool,
|
||||||
|
hasCloseButton: null == hasCloseButton
|
||||||
|
? _value.hasCloseButton
|
||||||
|
: hasCloseButton // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
) as $Val);
|
) as $Val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ abstract class _$$NfcViewImplCopyWith<$Res> implements $NfcViewCopyWith<$Res> {
|
|||||||
__$$NfcViewImplCopyWithImpl<$Res>;
|
__$$NfcViewImplCopyWithImpl<$Res>;
|
||||||
@override
|
@override
|
||||||
@useResult
|
@useResult
|
||||||
$Res call({bool isShowing, Widget child, bool? showCloseButton});
|
$Res call({Widget child, bool visible, bool hasCloseButton});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -93,23 +93,23 @@ class __$$NfcViewImplCopyWithImpl<$Res>
|
|||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
@override
|
@override
|
||||||
$Res call({
|
$Res call({
|
||||||
Object? isShowing = null,
|
|
||||||
Object? child = null,
|
Object? child = null,
|
||||||
Object? showCloseButton = freezed,
|
Object? visible = null,
|
||||||
|
Object? hasCloseButton = null,
|
||||||
}) {
|
}) {
|
||||||
return _then(_$NfcViewImpl(
|
return _then(_$NfcViewImpl(
|
||||||
isShowing: null == isShowing
|
|
||||||
? _value.isShowing
|
|
||||||
: isShowing // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
child: null == child
|
child: null == child
|
||||||
? _value.child
|
? _value.child
|
||||||
: child // ignore: cast_nullable_to_non_nullable
|
: child // ignore: cast_nullable_to_non_nullable
|
||||||
as Widget,
|
as Widget,
|
||||||
showCloseButton: freezed == showCloseButton
|
visible: null == visible
|
||||||
? _value.showCloseButton
|
? _value.visible
|
||||||
: showCloseButton // ignore: cast_nullable_to_non_nullable
|
: visible // ignore: cast_nullable_to_non_nullable
|
||||||
as bool?,
|
as bool,
|
||||||
|
hasCloseButton: null == hasCloseButton
|
||||||
|
? _value.hasCloseButton
|
||||||
|
: hasCloseButton // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,18 +118,20 @@ class __$$NfcViewImplCopyWithImpl<$Res>
|
|||||||
|
|
||||||
class _$NfcViewImpl implements _NfcView {
|
class _$NfcViewImpl implements _NfcView {
|
||||||
_$NfcViewImpl(
|
_$NfcViewImpl(
|
||||||
{required this.isShowing, required this.child, this.showCloseButton});
|
{required this.child, this.visible = false, this.hasCloseButton = false});
|
||||||
|
|
||||||
@override
|
|
||||||
final bool isShowing;
|
|
||||||
@override
|
@override
|
||||||
final Widget child;
|
final Widget child;
|
||||||
@override
|
@override
|
||||||
final bool? showCloseButton;
|
@JsonKey()
|
||||||
|
final bool visible;
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final bool hasCloseButton;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'NfcView(isShowing: $isShowing, child: $child, showCloseButton: $showCloseButton)';
|
return 'NfcView(child: $child, visible: $visible, hasCloseButton: $hasCloseButton)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -137,16 +139,14 @@ class _$NfcViewImpl implements _NfcView {
|
|||||||
return identical(this, other) ||
|
return identical(this, other) ||
|
||||||
(other.runtimeType == runtimeType &&
|
(other.runtimeType == runtimeType &&
|
||||||
other is _$NfcViewImpl &&
|
other is _$NfcViewImpl &&
|
||||||
(identical(other.isShowing, isShowing) ||
|
|
||||||
other.isShowing == isShowing) &&
|
|
||||||
(identical(other.child, child) || other.child == child) &&
|
(identical(other.child, child) || other.child == child) &&
|
||||||
(identical(other.showCloseButton, showCloseButton) ||
|
(identical(other.visible, visible) || other.visible == visible) &&
|
||||||
other.showCloseButton == showCloseButton));
|
(identical(other.hasCloseButton, hasCloseButton) ||
|
||||||
|
other.hasCloseButton == hasCloseButton));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode => Object.hash(runtimeType, child, visible, hasCloseButton);
|
||||||
Object.hash(runtimeType, isShowing, child, showCloseButton);
|
|
||||||
|
|
||||||
/// Create a copy of NfcView
|
/// Create a copy of NfcView
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@ -159,16 +159,16 @@ class _$NfcViewImpl implements _NfcView {
|
|||||||
|
|
||||||
abstract class _NfcView implements NfcView {
|
abstract class _NfcView implements NfcView {
|
||||||
factory _NfcView(
|
factory _NfcView(
|
||||||
{required final bool isShowing,
|
{required final Widget child,
|
||||||
required final Widget child,
|
final bool visible,
|
||||||
final bool? showCloseButton}) = _$NfcViewImpl;
|
final bool hasCloseButton}) = _$NfcViewImpl;
|
||||||
|
|
||||||
@override
|
|
||||||
bool get isShowing;
|
|
||||||
@override
|
@override
|
||||||
Widget get child;
|
Widget get child;
|
||||||
@override
|
@override
|
||||||
bool? get showCloseButton;
|
bool get visible;
|
||||||
|
@override
|
||||||
|
bool get hasCloseButton;
|
||||||
|
|
||||||
/// Create a copy of NfcView
|
/// Create a copy of NfcView
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@ -177,133 +177,3 @@ abstract class _NfcView implements NfcView {
|
|||||||
_$$NfcViewImplCopyWith<_$NfcViewImpl> get copyWith =>
|
_$$NfcViewImplCopyWith<_$NfcViewImpl> get copyWith =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$NfcEventCommand {
|
|
||||||
NfcEvent get event => throw _privateConstructorUsedError;
|
|
||||||
|
|
||||||
/// Create a copy of NfcEventCommand
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
$NfcEventCommandCopyWith<NfcEventCommand> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $NfcEventCommandCopyWith<$Res> {
|
|
||||||
factory $NfcEventCommandCopyWith(
|
|
||||||
NfcEventCommand value, $Res Function(NfcEventCommand) then) =
|
|
||||||
_$NfcEventCommandCopyWithImpl<$Res, NfcEventCommand>;
|
|
||||||
@useResult
|
|
||||||
$Res call({NfcEvent event});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$NfcEventCommandCopyWithImpl<$Res, $Val extends NfcEventCommand>
|
|
||||||
implements $NfcEventCommandCopyWith<$Res> {
|
|
||||||
_$NfcEventCommandCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Val _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function($Val) _then;
|
|
||||||
|
|
||||||
/// Create a copy of NfcEventCommand
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? event = null,
|
|
||||||
}) {
|
|
||||||
return _then(_value.copyWith(
|
|
||||||
event: null == event
|
|
||||||
? _value.event
|
|
||||||
: event // ignore: cast_nullable_to_non_nullable
|
|
||||||
as NfcEvent,
|
|
||||||
) as $Val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$NfcEventCommandImplCopyWith<$Res>
|
|
||||||
implements $NfcEventCommandCopyWith<$Res> {
|
|
||||||
factory _$$NfcEventCommandImplCopyWith(_$NfcEventCommandImpl value,
|
|
||||||
$Res Function(_$NfcEventCommandImpl) then) =
|
|
||||||
__$$NfcEventCommandImplCopyWithImpl<$Res>;
|
|
||||||
@override
|
|
||||||
@useResult
|
|
||||||
$Res call({NfcEvent event});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$NfcEventCommandImplCopyWithImpl<$Res>
|
|
||||||
extends _$NfcEventCommandCopyWithImpl<$Res, _$NfcEventCommandImpl>
|
|
||||||
implements _$$NfcEventCommandImplCopyWith<$Res> {
|
|
||||||
__$$NfcEventCommandImplCopyWithImpl(
|
|
||||||
_$NfcEventCommandImpl _value, $Res Function(_$NfcEventCommandImpl) _then)
|
|
||||||
: super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of NfcEventCommand
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? event = null,
|
|
||||||
}) {
|
|
||||||
return _then(_$NfcEventCommandImpl(
|
|
||||||
event: null == event
|
|
||||||
? _value.event
|
|
||||||
: event // ignore: cast_nullable_to_non_nullable
|
|
||||||
as NfcEvent,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$NfcEventCommandImpl implements _NfcEventCommand {
|
|
||||||
_$NfcEventCommandImpl({this.event = const NfcEvent()});
|
|
||||||
|
|
||||||
@override
|
|
||||||
@JsonKey()
|
|
||||||
final NfcEvent event;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'NfcEventCommand(event: $event)';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType &&
|
|
||||||
other is _$NfcEventCommandImpl &&
|
|
||||||
(identical(other.event, event) || other.event == event));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => Object.hash(runtimeType, event);
|
|
||||||
|
|
||||||
/// Create a copy of NfcEventCommand
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
@override
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
_$$NfcEventCommandImplCopyWith<_$NfcEventCommandImpl> get copyWith =>
|
|
||||||
__$$NfcEventCommandImplCopyWithImpl<_$NfcEventCommandImpl>(
|
|
||||||
this, _$identity);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _NfcEventCommand implements NfcEventCommand {
|
|
||||||
factory _NfcEventCommand({final NfcEvent event}) = _$NfcEventCommandImpl;
|
|
||||||
|
|
||||||
@override
|
|
||||||
NfcEvent get event;
|
|
||||||
|
|
||||||
/// Create a copy of NfcEventCommand
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@override
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
_$$NfcEventCommandImplCopyWith<_$NfcEventCommandImpl> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
@ -37,8 +37,7 @@ class _NfcEventCommandListener {
|
|||||||
|
|
||||||
void startListener(BuildContext context) {
|
void startListener(BuildContext context) {
|
||||||
listener?.close();
|
listener?.close();
|
||||||
listener = _ref.listen(nfcEventCommandNotifier.select((c) => c.event),
|
listener = _ref.listen(nfcEventNotifier, (previous, action) {
|
||||||
(previous, action) {
|
|
||||||
_log.debug('Change in command for Overlay: $previous -> $action');
|
_log.debug('Change in command for Overlay: $previous -> $action');
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case (NfcSetViewEvent a):
|
case (NfcSetViewEvent a):
|
||||||
@ -49,11 +48,7 @@ class _NfcEventCommandListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (NfcHideViewEvent e):
|
case (NfcHideViewEvent e):
|
||||||
_hide(context, e.hideAfter);
|
_hide(context, e.delay);
|
||||||
break;
|
|
||||||
case (NfcCancelEvent _):
|
|
||||||
_ref.read(androidDialogProvider.notifier).cancelDialog();
|
|
||||||
_hide(context, Duration.zero);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -88,7 +83,8 @@ class _NfcEventCommandListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get visible => _ref.read(nfcViewNotifier.select((s) => s.isShowing));
|
bool get visible => _ref.read(nfcViewNotifier.select((s) => s.visible));
|
||||||
|
|
||||||
set visible(bool showing) =>
|
set visible(bool showing) =>
|
||||||
_ref.read(nfcViewNotifier.notifier).setShowing(showing);
|
_ref.read(nfcViewNotifier.notifier).setShowing(showing);
|
||||||
}
|
}
|
||||||
|
@ -20,18 +20,17 @@ import 'package:material_symbols_icons/symbols.dart';
|
|||||||
|
|
||||||
import 'models.dart';
|
import 'models.dart';
|
||||||
|
|
||||||
final nfcEventCommandNotifier =
|
final nfcEventNotifier =
|
||||||
NotifierProvider<_NfcEventCommandNotifier, NfcEventCommand>(
|
NotifierProvider<_NfcEventNotifier, NfcEvent>(_NfcEventNotifier.new);
|
||||||
_NfcEventCommandNotifier.new);
|
|
||||||
|
|
||||||
class _NfcEventCommandNotifier extends Notifier<NfcEventCommand> {
|
class _NfcEventNotifier extends Notifier<NfcEvent> {
|
||||||
@override
|
@override
|
||||||
NfcEventCommand build() {
|
NfcEvent build() {
|
||||||
return NfcEventCommand(event: const NfcEvent());
|
return const NfcEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCommand(NfcEventCommand command) {
|
void send(NfcEvent event) {
|
||||||
state = command;
|
state = event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ final nfcViewNotifier =
|
|||||||
class _NfcViewNotifier extends Notifier<NfcView> {
|
class _NfcViewNotifier extends Notifier<NfcView> {
|
||||||
@override
|
@override
|
||||||
NfcView build() {
|
NfcView build() {
|
||||||
return NfcView(isShowing: false, child: const SizedBox());
|
return NfcView(child: const SizedBox());
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Widget child) {
|
void update(Widget child) {
|
||||||
@ -49,12 +48,12 @@ class _NfcViewNotifier extends Notifier<NfcView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setShowing(bool value) {
|
void setShowing(bool value) {
|
||||||
state = state.copyWith(isShowing: value);
|
state = state.copyWith(visible: value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDialogProperties({bool? showCloseButton}) {
|
void setDialogProperties({bool? showCloseButton}) {
|
||||||
state = state.copyWith(
|
state =
|
||||||
showCloseButton: showCloseButton ?? state.showCloseButton);
|
state.copyWith(hasCloseButton: showCloseButton ?? state.hasCloseButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +64,7 @@ class NfcBottomSheet extends ConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final widget = ref.watch(nfcViewNotifier.select((s) => s.child));
|
final widget = ref.watch(nfcViewNotifier.select((s) => s.child));
|
||||||
final showCloseButton =
|
final showCloseButton =
|
||||||
ref.watch(nfcViewNotifier.select((s) => s.showCloseButton ?? false));
|
ref.watch(nfcViewNotifier.select((s) => s.hasCloseButton));
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
@ -22,13 +22,13 @@ import 'models.dart';
|
|||||||
import 'nfc_activity_overlay.dart';
|
import 'nfc_activity_overlay.dart';
|
||||||
import 'nfc_content_widget.dart';
|
import 'nfc_content_widget.dart';
|
||||||
|
|
||||||
NfcEventCommand autoClose(
|
NfcEvent autoClose(
|
||||||
{required String title,
|
{required String title,
|
||||||
required String subtitle,
|
required String subtitle,
|
||||||
required Widget icon,
|
required Widget icon,
|
||||||
bool showIfHidden = true}) =>
|
bool showIfHidden = true}) =>
|
||||||
setNfcView(
|
NfcSetViewEvent(
|
||||||
_NfcAutoCloseWidget(
|
child: _NfcAutoCloseWidget(
|
||||||
child: NfcContentWidget(
|
child: NfcContentWidget(
|
||||||
title: title,
|
title: title,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
@ -46,7 +46,7 @@ class _NfcAutoCloseWidget extends ConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
ref.listen(androidNfcActivityProvider, (previous, current) {
|
ref.listen(androidNfcActivityProvider, (previous, current) {
|
||||||
if (current == NfcActivity.ready) {
|
if (current == NfcActivity.ready) {
|
||||||
ref.read(nfcEventCommandNotifier.notifier).sendCommand(hideNfcView());
|
ref.read(nfcEventNotifier.notifier).send(const NfcHideViewEvent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -24,13 +24,14 @@ import 'models.dart';
|
|||||||
import 'nfc_activity_overlay.dart';
|
import 'nfc_activity_overlay.dart';
|
||||||
import 'nfc_content_widget.dart';
|
import 'nfc_content_widget.dart';
|
||||||
|
|
||||||
NfcEventCommand countDownClose({
|
NfcEvent countDownClose({
|
||||||
required String title,
|
required String title,
|
||||||
required String subtitle,
|
required String subtitle,
|
||||||
required Widget icon,
|
required Widget icon,
|
||||||
int closeInSec = 3,
|
int closeInSec = 3,
|
||||||
}) =>
|
}) =>
|
||||||
setNfcView(_CountDownCloseWidget(
|
NfcSetViewEvent(
|
||||||
|
child: _CountDownCloseWidget(
|
||||||
closeInSec: closeInSec,
|
closeInSec: closeInSec,
|
||||||
child: NfcContentWidget(
|
child: NfcContentWidget(
|
||||||
title: title,
|
title: title,
|
||||||
@ -109,6 +110,6 @@ class _CountDownCloseWidgetState extends ConsumerState<_CountDownCloseWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hideNow() {
|
void hideNow() {
|
||||||
ref.read(nfcEventCommandNotifier.notifier).sendCommand(hideNfcView());
|
ref.read(nfcEventNotifier.notifier).send(const NfcHideViewEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user