170 lines
4.9 KiB
Dart
170 lines
4.9 KiB
Dart
import 'package:app/utils/time.dart';
|
|
import 'package:app/widgets/base/button/index.dart';
|
|
import 'package:app/widgets/base/config/config.dart';
|
|
import 'package:app/widgets/base/dialog/config_dialog.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:remixicon/remixicon.dart';
|
|
|
|
import '../../../../widgets/room/core/count_down_vm.dart';
|
|
import '../viewmodel/tch_room_vm.dart';
|
|
import '../viewmodel/type.dart';
|
|
|
|
class TopBar extends StatelessWidget implements PreferredSizeWidget {
|
|
const TopBar({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final vm = context.watch<TchRoomVM>();
|
|
|
|
return AppBar(
|
|
backgroundColor: Color(0xff373c3e),
|
|
foregroundColor: Colors.white,
|
|
title: Column(
|
|
spacing: 5,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(vm.roomInfo.roomName, style: TextStyle(color: Colors.white, fontSize: 18)),
|
|
Row(
|
|
spacing: 15,
|
|
children: [
|
|
Consumer<CountDownVM>(
|
|
builder: (context, countVM, __) {
|
|
return _infoItem(
|
|
context,
|
|
title: "剩余 ${formatSeconds(countVM.endCountDown)}",
|
|
icon: RemixIcons.time_line,
|
|
);
|
|
},
|
|
),
|
|
_infoItem(
|
|
context,
|
|
title: "${vm.students.length} 名学生",
|
|
icon: RemixIcons.group_line,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
_actionButton(
|
|
context,
|
|
icon: RemixIcons.video_on_ai_line,
|
|
title: "关闭全部",
|
|
onPressed: () {
|
|
_closeAll(context, StudentAction.camera);
|
|
},
|
|
),
|
|
_actionButton(
|
|
context,
|
|
icon: RemixIcons.volume_up_line,
|
|
title: "全部静音",
|
|
onPressed: () {
|
|
_closeAll(context, StudentAction.speaker);
|
|
},
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(right: 15),
|
|
child: Button(
|
|
text: "白板",
|
|
textStyle: TextStyle(fontSize: 14),
|
|
onPressed: (){},
|
|
),
|
|
),
|
|
Consumer<TchRoomVM>(
|
|
builder: (context, vm, _) {
|
|
if (vm.roomInfo.roomStatus != 1) {
|
|
return SizedBox();
|
|
}
|
|
return Button(
|
|
type: ThemeType.danger,
|
|
textStyle: TextStyle(fontSize: 14),
|
|
text: "结束自习室",
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) {
|
|
return ConfigDialog(
|
|
content: '是否结束自习室?结束后无法在进入',
|
|
onCancel: () {
|
|
context.pop();
|
|
},
|
|
onConfirm: () {
|
|
context.pop();
|
|
vm.endRoom();
|
|
EasyLoading.showToast("会议室已结束");
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
SizedBox(width: 10),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _infoItem(BuildContext context, {required String title, required IconData icon}) {
|
|
return Row(
|
|
children: [
|
|
Icon(icon, color: Colors.white54, size: 14),
|
|
SizedBox(width: 4),
|
|
Text(title, style: TextStyle(fontSize: 12, color: Colors.white54)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _actionButton(
|
|
BuildContext context, {
|
|
required IconData icon,
|
|
required String title,
|
|
required VoidCallback onPressed,
|
|
}) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
margin: EdgeInsets.only(right: 15),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xff4a4f4f),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: InkWell(
|
|
onTap: onPressed,
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, size: 16),
|
|
SizedBox(width: 8),
|
|
Text(title, style: TextStyle(fontSize: 14)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _closeAll(BuildContext context, StudentAction action) {
|
|
final vm = context.read<TchRoomVM>();
|
|
String content = (action == StudentAction.camera) ? '是否关闭所有学生的摄像头?' : '是否关闭所有学生的扬声器?';
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) {
|
|
return ConfigDialog(
|
|
content: content,
|
|
onCancel: () => context.pop(),
|
|
onConfirm: () {
|
|
context.pop();
|
|
vm.closeAllStudentAction(action);
|
|
EasyLoading.showToast("操作已完成");
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
}
|