73 lines
2.2 KiB
Dart
73 lines
2.2 KiB
Dart
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:vibration/vibration.dart';
|
|
|
|
import '../bloc/remote_control_cubit.dart';
|
|
|
|
class RightJoystickArea extends StatelessWidget {
|
|
final bool isLocked;
|
|
final double width;
|
|
|
|
const RightJoystickArea({
|
|
Key? key,
|
|
required this.isLocked,
|
|
required this.width,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min, // 垂直方向紧凑布局
|
|
children: [
|
|
// 1. 交互锁定逻辑:对应 Compose 的 isLocked 判断
|
|
IgnorePointer(
|
|
ignoring: isLocked,
|
|
child: AnimatedOpacity(
|
|
duration: const Duration(milliseconds: 300),
|
|
opacity: isLocked ? 0.3 : 1.0, // 锁定后变透明/灰色
|
|
child: CCJoystick(
|
|
radius: width, // 对应 size(200.dp)
|
|
axisHint: AxisHint.leftRight, // 关键:指定为左右控制
|
|
onValueChanged: (value) {
|
|
// 对应 viewModel.updateOriginX(x)
|
|
/// context.read<RemoteControlCubit>().updateOriginY(value.x);
|
|
context.read<RemoteControlCubit>().updateOriginX(value.x);
|
|
_triggerVibration();
|
|
},
|
|
onPress: () {
|
|
_triggerVibration();
|
|
}
|
|
,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 18),
|
|
// 2. 底部文字:对应 Text("左右控制", color = Color.Gray)
|
|
Text(
|
|
"左右控制",
|
|
style: TextStyle(
|
|
color: Colors.white.withValues(alpha: 0.5),
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
],
|
|
);
|
|
}
|
|
void _triggerVibration() {
|
|
Vibration.hasVibrator().then((hasVibrator) {
|
|
if (hasVibrator ?? false) {
|
|
Vibration.vibrate(duration: 100);
|
|
debugPrint('📳 [右摇杆] 震动执行 - 100ms');
|
|
} else {
|
|
debugPrint('⚠️ [右摇杆] 设备不支持震动');
|
|
}
|
|
}).catchError((e) {
|
|
debugPrint('❌ [右摇杆] 震动失败:$e');
|
|
});
|
|
}
|
|
}
|