chatapp3-flutter/lib/ui_kit/widgets/room/seat/room_seat_widget.dart

240 lines
7.9 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:yumi/services/audio/rtc_manager.dart';
import '../../../../modules/room/seat/sc_seat_item.dart';
class RoomSeatWidget extends StatefulWidget {
const RoomSeatWidget({super.key});
@override
State<RoomSeatWidget> createState() => _RoomSeatWidgetState();
}
class _RoomSeatWidgetState extends State<RoomSeatWidget> {
int _lastSeatCount = 0;
int _normalizeSeatCount(int? seatCount) {
switch (seatCount) {
case 5:
case 10:
case 15:
case 20:
return seatCount ?? 0;
default:
return 0;
}
}
int _resolvedSeatCount(_RoomSeatLayoutSnapshot snapshot) {
final int liveSeatCount = _normalizeSeatCount(snapshot.seatCount);
final int configuredSeatCount = _normalizeSeatCount(
snapshot.configuredSeatCount,
);
final int seatCount =
liveSeatCount > 0 ? liveSeatCount : configuredSeatCount;
if (!snapshot.isExitingCurrentVoiceRoomSession && seatCount > 0) {
_lastSeatCount = seatCount;
}
if (snapshot.isExitingCurrentVoiceRoomSession && _lastSeatCount > 0) {
return _lastSeatCount;
}
return seatCount;
}
@override
Widget build(BuildContext context) {
return Selector<RtcProvider, _RoomSeatLayoutSnapshot>(
selector:
(context, provider) => _RoomSeatLayoutSnapshot(
seatCount: provider.roomWheatMap.length,
configuredSeatCount:
provider.currenRoom?.roomProfile?.roomSetting?.mikeSize
?.toInt() ??
0,
isExitingCurrentVoiceRoomSession:
provider.isExitingCurrentVoiceRoomSession,
),
builder: (context, snapshot, child) {
final int seatCount = _resolvedSeatCount(snapshot);
return seatCount == 5
? _buildSeat5()
: (seatCount == 10
? _buildSeat10()
: (seatCount == 15
? _buildSeat15()
: (seatCount == 20
? _buildSeat20()
: Container(height: 180.w))));
},
);
}
_buildSeat5() {
return Container(
margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 0)),
Expanded(flex: 1, child: SCSeatItem(index: 1)),
Expanded(flex: 1, child: SCSeatItem(index: 2)),
Expanded(flex: 1, child: SCSeatItem(index: 3)),
Expanded(flex: 1, child: SCSeatItem(index: 4)),
],
),
],
),
);
}
_buildSeat10() {
return Container(
margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 0)),
Expanded(flex: 1, child: SCSeatItem(index: 1)),
Expanded(flex: 1, child: SCSeatItem(index: 2)),
Expanded(flex: 1, child: SCSeatItem(index: 3)),
Expanded(flex: 1, child: SCSeatItem(index: 4)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(flex: 1, child: SCSeatItem(index: 5)),
Expanded(flex: 1, child: SCSeatItem(index: 6)),
Expanded(flex: 1, child: SCSeatItem(index: 7)),
Expanded(flex: 1, child: SCSeatItem(index: 8)),
Expanded(flex: 1, child: SCSeatItem(index: 9)),
],
),
],
),
);
}
_buildSeat15() {
return Container(
margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 0)),
Expanded(flex: 1, child: SCSeatItem(index: 1)),
Expanded(flex: 1, child: SCSeatItem(index: 2)),
Expanded(flex: 1, child: SCSeatItem(index: 3)),
Expanded(flex: 1, child: SCSeatItem(index: 4)),
],
),
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 5)),
Expanded(flex: 1, child: SCSeatItem(index: 6)),
Expanded(flex: 1, child: SCSeatItem(index: 7)),
Expanded(flex: 1, child: SCSeatItem(index: 8)),
Expanded(flex: 1, child: SCSeatItem(index: 9)),
],
),
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 10)),
Expanded(flex: 1, child: SCSeatItem(index: 11)),
Expanded(flex: 1, child: SCSeatItem(index: 12)),
Expanded(flex: 1, child: SCSeatItem(index: 13)),
Expanded(flex: 1, child: SCSeatItem(index: 14)),
],
),
],
),
);
}
_buildSeat20() {
return Container(
margin: EdgeInsets.only(top: 3.w, left: 10.w, right: 10.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 0)),
Expanded(flex: 1, child: SCSeatItem(index: 1)),
Expanded(flex: 1, child: SCSeatItem(index: 2)),
Expanded(flex: 1, child: SCSeatItem(index: 3)),
Expanded(flex: 1, child: SCSeatItem(index: 4)),
],
),
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 5)),
Expanded(flex: 1, child: SCSeatItem(index: 6)),
Expanded(flex: 1, child: SCSeatItem(index: 7)),
Expanded(flex: 1, child: SCSeatItem(index: 8)),
Expanded(flex: 1, child: SCSeatItem(index: 9)),
],
),
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 10)),
Expanded(flex: 1, child: SCSeatItem(index: 11)),
Expanded(flex: 1, child: SCSeatItem(index: 12)),
Expanded(flex: 1, child: SCSeatItem(index: 13)),
Expanded(flex: 1, child: SCSeatItem(index: 14)),
],
),
Row(
children: [
Expanded(flex: 1, child: SCSeatItem(index: 15)),
Expanded(flex: 1, child: SCSeatItem(index: 16)),
Expanded(flex: 1, child: SCSeatItem(index: 17)),
Expanded(flex: 1, child: SCSeatItem(index: 18)),
Expanded(flex: 1, child: SCSeatItem(index: 19)),
],
),
],
),
);
}
}
class _RoomSeatLayoutSnapshot {
const _RoomSeatLayoutSnapshot({
required this.seatCount,
required this.configuredSeatCount,
required this.isExitingCurrentVoiceRoomSession,
});
final int seatCount;
final int configuredSeatCount;
final bool isExitingCurrentVoiceRoomSession;
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
return other is _RoomSeatLayoutSnapshot &&
other.seatCount == seatCount &&
other.configuredSeatCount == configuredSeatCount &&
other.isExitingCurrentVoiceRoomSession ==
isExitingCurrentVoiceRoomSession;
}
@override
int get hashCode => Object.hash(
seatCount,
configuredSeatCount,
isExitingCurrentVoiceRoomSession,
);
}