完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../components/capsule_toast.dart';
|
||||
import '../../../../core/localization/app_localizations.dart';
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
|
||||
/// Shared by both control entry points. Telemetry rebuilds never repeat a toast.
|
||||
class PermissionRequestFeedback extends StatelessWidget {
|
||||
const PermissionRequestFeedback({
|
||||
super.key,
|
||||
required this.cubit,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final RemoteControlCubit cubit;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
BlocListener<RemoteControlCubit, RemoteControlState>(
|
||||
bloc: cubit,
|
||||
listenWhen: (previous, current) =>
|
||||
previous.permissionFeedbackId != current.permissionFeedbackId &&
|
||||
current.permissionFeedbackKey.isNotEmpty,
|
||||
listener: (context, state) => CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.' + state.permissionFeedbackKey),
|
||||
duration: const Duration(seconds: 3),
|
||||
showCheck:
|
||||
state.permissionRequestPhase == PermissionRequestPhase.granted,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
String permissionStatusText(BuildContext context, RemoteControlState state) {
|
||||
final key = switch (state.permissionRequestPhase) {
|
||||
PermissionRequestPhase.checking => 'permission_checking',
|
||||
PermissionRequestPhase.sending => 'permission_sending',
|
||||
PermissionRequestPhase.waiting => 'permission_waiting',
|
||||
PermissionRequestPhase.timedOut => 'permission_unconfirmed',
|
||||
PermissionRequestPhase.failed when !state.hasPermission =>
|
||||
'permission_request_failed',
|
||||
_ => state.hasPermission ? 'controlling' : 'not_controlling',
|
||||
};
|
||||
return AppLocalizations.of(context).translate('remote_control.' + key);
|
||||
}
|
||||
|
||||
String permissionStatusHint(BuildContext context, RemoteControlState state) =>
|
||||
state.permissionFeedbackKey.isEmpty
|
||||
? permissionStatusText(context, state)
|
||||
: AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.' + state.permissionFeedbackKey);
|
||||
Reference in New Issue
Block a user