210 lines
7.1 KiB
Dart
210 lines
7.1 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 {
|
|
@override
|
|
_RoomSeatWidgetState createState() => _RoomSeatWidgetState();
|
|
}
|
|
|
|
class _RoomSeatWidgetState extends State<RoomSeatWidget> {
|
|
int _lastSeatCount = 0;
|
|
|
|
int _resolvedSeatCount(_RoomSeatLayoutSnapshot snapshot) {
|
|
final int seatCount = snapshot.seatCount;
|
|
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,
|
|
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.isExitingCurrentVoiceRoomSession,
|
|
});
|
|
|
|
final int seatCount;
|
|
final bool isExitingCurrentVoiceRoomSession;
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
return other is _RoomSeatLayoutSnapshot &&
|
|
other.seatCount == seatCount &&
|
|
other.isExitingCurrentVoiceRoomSession ==
|
|
isExitingCurrentVoiceRoomSession;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => Object.hash(seatCount, isExitingCurrentVoiceRoomSession);
|
|
}
|