Changed capacity to int
This commit is contained in:
parent
8cc377a3f4
commit
11c986131f
4 changed files with 24 additions and 18 deletions
|
|
@ -5,7 +5,7 @@ extension EventsRoomExtension on Room {
|
|||
await postLoad();
|
||||
if (!isRoomAdmin &&
|
||||
(_capacity != null) &&
|
||||
(await _numNonAdmins) >= (int.parse(_capacity!))) {
|
||||
(await _numNonAdmins) >= (_capacity!)) {
|
||||
if (!isSpace) {
|
||||
markUnread(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,10 +246,10 @@ extension PangeaRoom on Room {
|
|||
|
||||
// room_settings
|
||||
|
||||
Future<String> updateRoomCapacity(String newCapacity) =>
|
||||
Future<void> updateRoomCapacity(int newCapacity) =>
|
||||
_updateRoomCapacity(newCapacity);
|
||||
|
||||
String? get capacity => _capacity;
|
||||
int? get capacity => _capacity;
|
||||
|
||||
PangeaRoomRules? get pangeaRoomRules => _pangeaRoomRules;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension RoomSettingsRoomExtension on Room {
|
||||
Future<String> _updateRoomCapacity(String newCapacity) =>
|
||||
Future<void> _updateRoomCapacity(int newCapacity) =>
|
||||
client.setRoomStateWithKey(
|
||||
id,
|
||||
PangeaEventTypes.capacity,
|
||||
|
|
@ -9,9 +9,9 @@ extension RoomSettingsRoomExtension on Room {
|
|||
{'capacity': newCapacity},
|
||||
);
|
||||
|
||||
String? get _capacity {
|
||||
int? get _capacity {
|
||||
final t = getState(PangeaEventTypes.capacity)?.content['capacity'];
|
||||
return t is String ? t : null;
|
||||
return t is int ? t : null;
|
||||
}
|
||||
|
||||
PangeaRoomRules? get _pangeaRoomRules {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class RoomCapacityButton extends StatefulWidget {
|
|||
class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
||||
Room? room;
|
||||
ChatDetailsController? controller;
|
||||
String? capacity;
|
||||
int? capacity;
|
||||
String? nonAdmins;
|
||||
|
||||
RoomCapacityButtonState({Key? key});
|
||||
|
|
@ -45,7 +45,7 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
if ((room?.isRoomAdmin ?? false) &&
|
||||
capacity != null &&
|
||||
nonAdmins != null &&
|
||||
int.parse(nonAdmins!) > int.parse(capacity!)) {
|
||||
int.parse(nonAdmins!) > capacity!) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
|
|
@ -70,9 +70,11 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
child: const Icon(Icons.reduce_capacity),
|
||||
),
|
||||
subtitle: Text(
|
||||
(capacity != null && nonAdmins != null)
|
||||
? '$nonAdmins/$capacity'
|
||||
: (capacity ?? L10n.of(context)!.capacityNotSet),
|
||||
(capacity == null)
|
||||
? L10n.of(context)!.capacityNotSet
|
||||
: (nonAdmins != null)
|
||||
? '$nonAdmins/$capacity'
|
||||
: '$capacity',
|
||||
),
|
||||
title: Text(
|
||||
L10n.of(context)!.roomCapacity,
|
||||
|
|
@ -86,13 +88,13 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> setCapacity(String newCapacity) async {
|
||||
Future<void> setCapacity(int newCapacity) async {
|
||||
capacity = newCapacity;
|
||||
}
|
||||
|
||||
Future<void> setClassCapacity() async {
|
||||
final TextEditingController myTextFieldController =
|
||||
TextEditingController(text: (capacity ?? ''));
|
||||
final TextEditingController capacityTextController =
|
||||
TextEditingController(text: (capacity != null ? '$capacity' : ''));
|
||||
showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
|
|
@ -101,7 +103,7 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
L10n.of(context)!.roomCapacity,
|
||||
),
|
||||
content: TextFormField(
|
||||
controller: myTextFieldController,
|
||||
controller: capacityTextController,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 3,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
|
|
@ -118,14 +120,18 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
TextButton(
|
||||
child: Text(L10n.of(context)!.ok),
|
||||
onPressed: () async {
|
||||
if (myTextFieldController.text == "") return;
|
||||
// Check if text field empty or non-int
|
||||
final newCapacity = int.tryParse(capacityTextController.text);
|
||||
if (newCapacity == null || capacityTextController.text == "") {
|
||||
return;
|
||||
}
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => ((room != null)
|
||||
? (room!.updateRoomCapacity(
|
||||
capacity = myTextFieldController.text,
|
||||
capacity = newCapacity,
|
||||
))
|
||||
: setCapacity(myTextFieldController.text)),
|
||||
: setCapacity(newCapacity)),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue