Added missing routes
and added a padding around the visibility selector
This commit is contained in:
parent
db5e950a93
commit
8e02de97c1
1 changed files with 288 additions and 280 deletions
|
@ -28,301 +28,123 @@ class _AboutRoomPageState extends State<AboutRoomPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textTheme = Theme.of(context)
|
final textTheme = Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.apply(displayColor: Theme.of(context).colorScheme.onSurface);
|
.apply(displayColor: Theme.of(context).colorScheme.onSurface);
|
||||||
|
|
||||||
double width = MediaQuery.of(context).size.width;
|
double width = MediaQuery.of(context).size.width;
|
||||||
double height = MediaQuery.of(context).size.height;
|
double height = MediaQuery.of(context).size.height;
|
||||||
double smallest = min(width, height);
|
double smallest = min(width, height);
|
||||||
|
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
// room meta display
|
// room meta display
|
||||||
...(widget.room != null)
|
...(widget.room != null)
|
||||||
? [
|
? [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(14),
|
padding: const EdgeInsets.all(14),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
SvgPicture.asset(
|
SvgPicture.asset(
|
||||||
(widget.room?.icon?.img)!,
|
(widget.room?.icon?.img)!,
|
||||||
width: smallest * 0.2,
|
width: smallest * 0.2,
|
||||||
height: smallest * 0.2,
|
height: smallest * 0.2,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
widget.room?.name ?? '',
|
widget.room?.name ?? '',
|
||||||
style: textTheme.displayMedium,
|
style: textTheme.displayMedium,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'${widget.room?.id}@${widget.room?.serverTag}',
|
'${widget.room?.id}@${widget.room?.serverTag}',
|
||||||
style: textTheme.bodySmall,
|
style: textTheme.bodySmall,
|
||||||
),
|
),
|
||||||
Text(widget.room?.description ?? '',
|
Text(widget.room?.description ?? '',
|
||||||
style: textTheme.bodyMedium),
|
style: textTheme.bodyMedium),
|
||||||
SegmentedButton<int>(
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: SegmentedButton<int>(
|
||||||
showSelectedIcon: true,
|
showSelectedIcon: true,
|
||||||
multiSelectionEnabled: false,
|
multiSelectionEnabled: false,
|
||||||
emptySelectionAllowed: false,
|
emptySelectionAllowed: false,
|
||||||
segments: RoomVisibility.list().map((vis) {
|
segments: RoomVisibility.list().map((vis) {
|
||||||
return ButtonSegment<int>(
|
return ButtonSegment<int>(
|
||||||
value: vis.type,
|
value: vis.type,
|
||||||
label: Text(vis.text),
|
label: Text(vis.text),
|
||||||
icon: Icon(vis.icon));
|
icon: Icon(vis.icon));
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onSelectionChanged: ((vset) {
|
onSelectionChanged: ((vset) {
|
||||||
// check permission
|
// check permission
|
||||||
// only show confirm dialog when user
|
// only show confirm dialog when user
|
||||||
// is admin, owner or has CHANGE_ADMIN permission
|
// is admin, owner or has CHANGE_ADMIN permission
|
||||||
if (widget.info == null ||
|
if (widget.info == null ||
|
||||||
(!(widget.info?.isAdmin ?? false) &&
|
(!(widget.info?.isAdmin ?? false) &&
|
||||||
!(widget.info?.isOwner ?? false) &&
|
!(widget.info?.isOwner ?? false) &&
|
||||||
((widget.info?.permissions)! &
|
((widget.info?.permissions)! &
|
||||||
RoomPermission.ota ==
|
RoomPermission.ota ==
|
||||||
0))) {
|
0))) {
|
||||||
// action not permitted
|
// action not permitted
|
||||||
// NOTE: no error dialog should be shown
|
// NOTE: no error dialog should be shown
|
||||||
// because the action is supposed to be hidden
|
// because the action is supposed to be hidden
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final vis = RoomVisibility(vset.first);
|
final vis = RoomVisibility(vset.first);
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
title: const Text('Change room visibility'),
|
title:
|
||||||
content: Text(
|
const Text('Change room visibility'),
|
||||||
'Do you really want to change the room visibility to: ${vis.text}'),
|
content: Text(
|
||||||
actions: [
|
'Do you really want to change the room visibility to: ${vis.text}'),
|
||||||
TextButton(
|
actions: [
|
||||||
onPressed: () {
|
TextButton(
|
||||||
Navigator.of(context).pop();
|
onPressed: () {
|
||||||
},
|
Navigator.of(context).pop();
|
||||||
child: const Text('Cancel'),
|
},
|
||||||
),
|
child: const Text('Cancel'),
|
||||||
FilledButton(
|
),
|
||||||
onPressed: () async {
|
FilledButton(
|
||||||
final scaffMgr =
|
onPressed: () async {
|
||||||
ScaffoldMessenger.of(context);
|
final scaffMgr =
|
||||||
final nav = Navigator.of(context);
|
ScaffoldMessenger.of(context);
|
||||||
|
final nav = Navigator.of(context);
|
||||||
|
|
||||||
User user;
|
User user;
|
||||||
try {
|
try {
|
||||||
user = await User.fromDisk();
|
user = await User.fromDisk();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// probably not logged in
|
// probably not logged in
|
||||||
nav.pop();
|
nav.pop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final resp =
|
final resp =
|
||||||
await postWithCreadentials(
|
await postWithCreadentials(
|
||||||
path: 'setVisibility',
|
path: 'setVisibility',
|
||||||
target: user.server,
|
target: user.server,
|
||||||
body: {
|
body: {
|
||||||
'room': widget.room?.id,
|
'room': widget.room?.id,
|
||||||
'server': (widget
|
'server': (widget
|
||||||
.room?.serverTag)!,
|
.room?.serverTag)!,
|
||||||
'visibility': vset.first
|
'visibility': vset.first
|
||||||
},
|
},
|
||||||
credentials: user);
|
credentials: user);
|
||||||
if (resp.res == Result.ok) {
|
if (resp.res == Result.ok) {
|
||||||
Room r = widget.room!;
|
Room r = widget.room!;
|
||||||
r.visibility = vis;
|
r.visibility = vis;
|
||||||
r.toDisk();
|
r.toDisk();
|
||||||
} else {
|
} else {
|
||||||
// server error
|
// server error
|
||||||
final snackBar = SnackBar(
|
|
||||||
behavior:
|
|
||||||
SnackBarBehavior.floating,
|
|
||||||
content: Text(
|
|
||||||
errorAsString(resp.body)),
|
|
||||||
action: SnackBarAction(
|
|
||||||
label: 'Dismiss',
|
|
||||||
onPressed: () {
|
|
||||||
scaffMgr
|
|
||||||
.hideCurrentSnackBar();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
scaffMgr.hideCurrentSnackBar();
|
|
||||||
scaffMgr.showSnackBar(snackBar);
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
// network error
|
|
||||||
final snackBar = SnackBar(
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
content:
|
|
||||||
const Text('Network error'),
|
|
||||||
action: SnackBarAction(
|
|
||||||
label: 'Dismiss',
|
|
||||||
onPressed: () {
|
|
||||||
scaffMgr.hideCurrentSnackBar();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
scaffMgr.hideCurrentSnackBar();
|
|
||||||
scaffMgr.showSnackBar(snackBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.pop();
|
|
||||||
},
|
|
||||||
child: const Text('Ok'),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}),
|
|
||||||
selected: {(widget.room?.visibility?.type)!},
|
|
||||||
selectedIcon: Icon((widget.room?.visibility?.icon)!),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
// edit room meta button
|
|
||||||
...(widget.info != null &&
|
|
||||||
((widget.info?.isAdmin ?? false) ||
|
|
||||||
(widget.info?.isOwner ?? false) ||
|
|
||||||
((widget.info?.permissions)! &
|
|
||||||
RoomPermission.changeMeta !=
|
|
||||||
0)))
|
|
||||||
? [
|
|
||||||
ListTile(
|
|
||||||
trailing: const Icon(Icons.chevron_right),
|
|
||||||
title: const Text('Edit Metadata'),
|
|
||||||
subtitle: const Text(
|
|
||||||
'Change the rooms name, description and icon'),
|
|
||||||
onTap: () {
|
|
||||||
// TODO: show edit room screen
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
// open members view
|
|
||||||
ListTile(
|
|
||||||
trailing: const Icon(Icons.chevron_right),
|
|
||||||
title: const Text('Members'),
|
|
||||||
subtitle: const Text('Show Member list'),
|
|
||||||
onTap: () {
|
|
||||||
// TODO: open member view screen
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...(widget.info != null &&
|
|
||||||
((widget.info?.isAdmin ?? false) ||
|
|
||||||
(widget.info?.isOwner ?? false) ||
|
|
||||||
((widget.info?.permissions)! & RoomPermission.ota !=
|
|
||||||
0)))
|
|
||||||
? [
|
|
||||||
ListTile(
|
|
||||||
trailing: const Icon(Icons.chevron_right),
|
|
||||||
title: const Text('OTA'),
|
|
||||||
subtitle: const Text('Manage and delete OTAs'),
|
|
||||||
onTap: () {
|
|
||||||
// TODO: show manage ota screen
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
|
|
||||||
...(widget.info != null)
|
|
||||||
? [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: FilledButton.tonal(
|
|
||||||
child: Text(((widget.info?.isOwner)!)
|
|
||||||
? 'Delete Room'
|
|
||||||
: 'Leave Room'),
|
|
||||||
onPressed: () {
|
|
||||||
// show confirm dialog
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (ctx) => AlertDialog(
|
|
||||||
title: Text(((widget.info?.isOwner)!)
|
|
||||||
? 'Delete Room'
|
|
||||||
: 'Leave Room'),
|
|
||||||
content: Text(
|
|
||||||
'Do you really want to ${((widget.info?.isOwner)!) ? "delete" : "leave"} the room?'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
// close popup
|
|
||||||
Navigator.of(ctx).pop();
|
|
||||||
},
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: () async {
|
|
||||||
// send request
|
|
||||||
final scaffMgr =
|
|
||||||
ScaffoldMessenger.of(ctx);
|
|
||||||
final nav = Navigator.of(ctx);
|
|
||||||
final rmaster = Routemaster.of(ctx);
|
|
||||||
|
|
||||||
User user;
|
|
||||||
try {
|
|
||||||
user = await User.fromDisk();
|
|
||||||
} catch (_) {
|
|
||||||
// probably not logged in
|
|
||||||
nav.pop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final resp = await postWithCreadentials(
|
|
||||||
path: ((widget.info?.isOwner)!)
|
|
||||||
? 'deleteRoom'
|
|
||||||
: 'leaveRoom',
|
|
||||||
target: user.server,
|
|
||||||
body: {
|
|
||||||
'room': widget.room?.id,
|
|
||||||
'server':
|
|
||||||
(widget.room?.serverTag)!,
|
|
||||||
},
|
|
||||||
credentials: user);
|
|
||||||
if (resp.res == Result.ok) {
|
|
||||||
// try delete room from disk
|
|
||||||
try {
|
|
||||||
await widget.room?.removeDisk();
|
|
||||||
} catch (_) {}
|
|
||||||
|
|
||||||
// go back home
|
|
||||||
rmaster.replace('/');
|
|
||||||
} else {
|
|
||||||
// server error
|
|
||||||
final snackBar = SnackBar(
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
content:
|
|
||||||
Text(errorAsString(resp.body)),
|
|
||||||
action: SnackBarAction(
|
|
||||||
label: 'Dismiss',
|
|
||||||
onPressed: () {
|
|
||||||
scaffMgr.hideCurrentSnackBar();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
scaffMgr.hideCurrentSnackBar();
|
|
||||||
scaffMgr.showSnackBar(snackBar);
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
// network error
|
|
||||||
final snackBar = SnackBar(
|
final snackBar = SnackBar(
|
||||||
behavior: SnackBarBehavior.floating,
|
behavior:
|
||||||
content: const Text('Network error'),
|
SnackBarBehavior.floating,
|
||||||
|
content: Text(
|
||||||
|
errorAsString(resp.body)),
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: 'Dismiss',
|
label: 'Dismiss',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
scaffMgr.hideCurrentSnackBar();
|
scaffMgr
|
||||||
|
.hideCurrentSnackBar();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -330,19 +152,205 @@ class _AboutRoomPageState extends State<AboutRoomPage> {
|
||||||
scaffMgr.hideCurrentSnackBar();
|
scaffMgr.hideCurrentSnackBar();
|
||||||
scaffMgr.showSnackBar(snackBar);
|
scaffMgr.showSnackBar(snackBar);
|
||||||
}
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// network error
|
||||||
|
final snackBar = SnackBar(
|
||||||
|
behavior:
|
||||||
|
SnackBarBehavior.floating,
|
||||||
|
content:
|
||||||
|
const Text('Network error'),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: 'Dismiss',
|
||||||
|
onPressed: () {
|
||||||
|
scaffMgr
|
||||||
|
.hideCurrentSnackBar();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// close popup
|
scaffMgr.hideCurrentSnackBar();
|
||||||
nav.pop();
|
scaffMgr.showSnackBar(snackBar);
|
||||||
},
|
}
|
||||||
child: Text(((widget.info?.isOwner)!)
|
|
||||||
? 'Delete'
|
nav.pop();
|
||||||
: 'Leave'),
|
},
|
||||||
)
|
child: const Text('Ok'),
|
||||||
],
|
)
|
||||||
));
|
],
|
||||||
|
));
|
||||||
|
}),
|
||||||
|
selected: {(widget.room?.visibility?.type)!},
|
||||||
|
selectedIcon: Icon((widget.room?.visibility?.icon)!),
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(14),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
// edit room meta button
|
||||||
|
...(widget.info != null &&
|
||||||
|
((widget.info?.isAdmin ?? false) ||
|
||||||
|
(widget.info?.isOwner ?? false) ||
|
||||||
|
((widget.info?.permissions)! &
|
||||||
|
RoomPermission.changeMeta !=
|
||||||
|
0)))
|
||||||
|
? [
|
||||||
|
ListTile(
|
||||||
|
trailing: const Icon(Icons.chevron_right),
|
||||||
|
title: const Text('Edit Metadata'),
|
||||||
|
subtitle: const Text(
|
||||||
|
'Change the rooms name, description and icon'),
|
||||||
|
onTap: () {
|
||||||
|
// show edit room screen
|
||||||
|
Routemaster.of(context).push('/r/${widget.room?.serverTag}/${widget.room?.id}/edit');
|
||||||
},
|
},
|
||||||
))
|
),
|
||||||
]
|
]
|
||||||
|
: [],
|
||||||
|
// open members view
|
||||||
|
ListTile(
|
||||||
|
trailing: const Icon(Icons.chevron_right),
|
||||||
|
title: const Text('Members'),
|
||||||
|
subtitle: const Text('Show Member list'),
|
||||||
|
onTap: () {
|
||||||
|
// open member view screen
|
||||||
|
Routemaster.of(context).push('/r/${widget.room?.serverTag}/${widget.room?.id}/members');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
...(widget.info != null &&
|
||||||
|
((widget.info?.isAdmin ?? false) ||
|
||||||
|
(widget.info?.isOwner ?? false) ||
|
||||||
|
((widget.info?.permissions)! & RoomPermission.ota !=
|
||||||
|
0)))
|
||||||
|
? [
|
||||||
|
ListTile(
|
||||||
|
trailing: const Icon(Icons.chevron_right),
|
||||||
|
title: const Text('OTA'),
|
||||||
|
subtitle: const Text('Manage and delete OTAs'),
|
||||||
|
onTap: () {
|
||||||
|
// show manage ota screen
|
||||||
|
Routemaster.of(context).push('/r/${widget.room?.serverTag}/${widget.room?.id}/ota');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
|
||||||
|
...(widget.info != null)
|
||||||
|
? [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: FilledButton.tonal(
|
||||||
|
child: Text(((widget.info?.isOwner)!)
|
||||||
|
? 'Delete Room'
|
||||||
|
: 'Leave Room'),
|
||||||
|
onPressed: () {
|
||||||
|
// show confirm dialog
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: Text(((widget.info?.isOwner)!)
|
||||||
|
? 'Delete Room'
|
||||||
|
: 'Leave Room'),
|
||||||
|
content: Text(
|
||||||
|
'Do you really want to ${((widget.info?.isOwner)!) ? "delete" : "leave"} the room?'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
// close popup
|
||||||
|
Navigator.of(ctx).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () async {
|
||||||
|
// send request
|
||||||
|
final scaffMgr =
|
||||||
|
ScaffoldMessenger.of(ctx);
|
||||||
|
final nav = Navigator.of(ctx);
|
||||||
|
final rmaster = Routemaster.of(ctx);
|
||||||
|
|
||||||
|
User user;
|
||||||
|
try {
|
||||||
|
user = await User.fromDisk();
|
||||||
|
} catch (_) {
|
||||||
|
// probably not logged in
|
||||||
|
nav.pop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final resp = await postWithCreadentials(
|
||||||
|
path: ((widget.info?.isOwner)!)
|
||||||
|
? 'deleteRoom'
|
||||||
|
: 'leaveRoom',
|
||||||
|
target: user.server,
|
||||||
|
body: {
|
||||||
|
'room': widget.room?.id,
|
||||||
|
'server':
|
||||||
|
(widget.room?.serverTag)!,
|
||||||
|
},
|
||||||
|
credentials: user);
|
||||||
|
if (resp.res == Result.ok) {
|
||||||
|
// try delete room from disk
|
||||||
|
try {
|
||||||
|
await widget.room?.removeDisk();
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
// go back home
|
||||||
|
rmaster.replace('/');
|
||||||
|
} else {
|
||||||
|
// server error
|
||||||
|
final snackBar = SnackBar(
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
content:
|
||||||
|
Text(errorAsString(resp.body)),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: 'Dismiss',
|
||||||
|
onPressed: () {
|
||||||
|
scaffMgr.hideCurrentSnackBar();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
scaffMgr.hideCurrentSnackBar();
|
||||||
|
scaffMgr.showSnackBar(snackBar);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// network error
|
||||||
|
final snackBar = SnackBar(
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
content: const Text('Network error'),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: 'Dismiss',
|
||||||
|
onPressed: () {
|
||||||
|
scaffMgr.hideCurrentSnackBar();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
scaffMgr.hideCurrentSnackBar();
|
||||||
|
scaffMgr.showSnackBar(snackBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// close popup
|
||||||
|
nav.pop();
|
||||||
|
},
|
||||||
|
child: Text(((widget.info?.isOwner)!)
|
||||||
|
? 'Delete'
|
||||||
|
: 'Leave'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
|
},
|
||||||
|
))
|
||||||
|
]
|
||||||
: [],
|
: [],
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue