USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../data/uvc_camera_service.dart';
|
||||
import '../cubit/usb_camera_cubit.dart';
|
||||
import '../cubit/usb_camera_state.dart';
|
||||
import '../widgets/usb_camera_preview.dart';
|
||||
import '../widgets/usb_camera_status_layer.dart';
|
||||
|
||||
/// USB 摄像头页:点击入口后直接尝试出画面,不展示额外步骤。
|
||||
class UsbCameraPage extends StatelessWidget {
|
||||
const UsbCameraPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => UsbCameraCubit(UvcCameraService())..start(),
|
||||
child: const _UsbCameraView(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _UsbCameraView extends StatelessWidget {
|
||||
const _UsbCameraView();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cubit = context.read<UsbCameraCubit>();
|
||||
|
||||
return BlocBuilder<UsbCameraCubit, UsbCameraState>(
|
||||
builder: (context, state) {
|
||||
return PopScope(
|
||||
canPop: state.phase != UsbCameraPhase.connecting &&
|
||||
state.phase != UsbCameraPhase.previewing,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) cubit.close(); // 先释放再返回
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () {
|
||||
cubit.close();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
title: const Text(
|
||||
'USB 摄像头',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: state.showPreview && state.selected != null
|
||||
? UsbCameraPreview(
|
||||
device: state.selected!,
|
||||
phase: state.phase,
|
||||
onReconnect: cubit.reconnect,
|
||||
aspectRatio: state.previewAspectRatio,
|
||||
)
|
||||
: UsbCameraStatusLayer(state: state, cubit: cubit),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user