Merged EditRoom and NewRoom page
and moved ChangeRoomIcon-Dialog into seperate file. This was done in an attempt to remove redundancy
This commit is contained in:
parent
4cfa4c2ad0
commit
8706122590
4 changed files with 347 additions and 515 deletions
50
lib/components/room_icon_picker.dart
Normal file
50
lib/components/room_icon_picker.dart
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:outbag_app/backend/room.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
class RoomIconPicker extends StatelessWidget {
|
||||||
|
Function(RoomIcon)? onSelect;
|
||||||
|
RoomIconPicker({this.onSelect});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
double width = MediaQuery.of(context).size.width;
|
||||||
|
double height = MediaQuery.of(context).size.height;
|
||||||
|
double smallest = min(min(width, height), 400);
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.chooseRoomIcon),
|
||||||
|
actions: const [],
|
||||||
|
content: SizedBox(
|
||||||
|
width: smallest * 0.3 * 3,
|
||||||
|
height: smallest * 0.3 * 3,
|
||||||
|
child: GridView.count(
|
||||||
|
crossAxisCount: 3,
|
||||||
|
children: RoomIcon.list().map((icon) {
|
||||||
|
return GridTile(
|
||||||
|
child: IconButton(
|
||||||
|
icon: SvgPicture.asset(
|
||||||
|
icon.img,
|
||||||
|
width: smallest * 0.3,
|
||||||
|
height: smallest * 0.3,
|
||||||
|
),
|
||||||
|
// do not display tooltip for now
|
||||||
|
// as it is hard to translate
|
||||||
|
// and the tooltip prevented the click event,
|
||||||
|
// when clicked on the tooltip bar
|
||||||
|
// tooltip:icon.text,
|
||||||
|
onPressed: () {
|
||||||
|
if (onSelect != null) {
|
||||||
|
onSelect!(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}).toList()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import 'package:outbag_app/screens/auth.dart';
|
||||||
import 'package:outbag_app/screens/room/new.dart';
|
import 'package:outbag_app/screens/room/new.dart';
|
||||||
import 'package:outbag_app/screens/room/join.dart';
|
import 'package:outbag_app/screens/room/join.dart';
|
||||||
import 'package:outbag_app/screens/room/main.dart';
|
import 'package:outbag_app/screens/room/main.dart';
|
||||||
import 'package:outbag_app/screens/room/about/edit.dart';
|
|
||||||
import 'package:outbag_app/screens/room/about/members.dart';
|
import 'package:outbag_app/screens/room/about/members.dart';
|
||||||
import 'package:outbag_app/screens/room/about/permissions.dart';
|
import 'package:outbag_app/screens/room/about/permissions.dart';
|
||||||
import 'package:outbag_app/screens/settings/main.dart';
|
import 'package:outbag_app/screens/settings/main.dart';
|
||||||
|
@ -218,8 +217,7 @@ class _OutbagAppState extends State {
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'new',
|
path: 'new',
|
||||||
name: 'new-room',
|
name: 'new-room',
|
||||||
builder: (context, state) =>
|
builder: (context, state) => NewRoomPage()),
|
||||||
const NewRoomPage()),
|
|
||||||
]),
|
]),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
name: 'room',
|
name: 'room',
|
||||||
|
@ -231,9 +229,9 @@ class _OutbagAppState extends State {
|
||||||
GoRoute(
|
GoRoute(
|
||||||
name: 'edit-room',
|
name: 'edit-room',
|
||||||
path: 'edit',
|
path: 'edit',
|
||||||
builder: (context, state) => EditRoomPage(
|
builder: (context, state) => NewRoomPage(
|
||||||
state.params['server'] ?? '',
|
server: state.params['server'] ?? '',
|
||||||
state.params['id'] ?? '')),
|
tag: state.params['id'] ?? '')),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
name: 'room-members',
|
name: 'room-members',
|
||||||
path: 'members',
|
path: 'members',
|
||||||
|
|
|
@ -1,299 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:outbag_app/backend/request.dart';
|
|
||||||
import 'package:outbag_app/backend/room.dart';
|
|
||||||
import 'package:outbag_app/backend/user.dart';
|
|
||||||
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
|
||||||
import 'package:outbag_app/tools/snackbar.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
class EditRoomPage extends StatefulWidget {
|
|
||||||
final String server;
|
|
||||||
final String tag;
|
|
||||||
|
|
||||||
const EditRoomPage(this.server, this.tag, {super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StatefulWidget> createState() => _EditRoomPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _EditRoomPageState extends State<EditRoomPage> {
|
|
||||||
final TextEditingController _ctrName = TextEditingController();
|
|
||||||
final TextEditingController _ctrID = TextEditingController();
|
|
||||||
final TextEditingController _ctrDescription = TextEditingController();
|
|
||||||
RoomIcon _ctrIcon = RoomIcon.other;
|
|
||||||
Room? room;
|
|
||||||
|
|
||||||
// show spinner by default
|
|
||||||
// until data has been fetched
|
|
||||||
bool showSpinner = true;
|
|
||||||
|
|
||||||
void initFromRoom(Room room) {
|
|
||||||
_ctrID.text = room.id;
|
|
||||||
_ctrName.text = room.name;
|
|
||||||
_ctrDescription.text = room.description;
|
|
||||||
_ctrIcon = room.icon!;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
this.room = room;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch room information
|
|
||||||
void fetchInfo() {
|
|
||||||
final sm = ScaffoldMessenger.of(context);
|
|
||||||
final router = GoRouter.of(context);
|
|
||||||
final user = context.read<User>();
|
|
||||||
|
|
||||||
doNetworkRequest(
|
|
||||||
sm,
|
|
||||||
req: () => postWithCreadentials(
|
|
||||||
path: 'getRoomInfo',
|
|
||||||
credentials: user,
|
|
||||||
target: user.server,
|
|
||||||
body: {'room': widget.tag, 'server': widget.server}),
|
|
||||||
onOK: (body) async {
|
|
||||||
final room = Room.fromJSON(body['data']);
|
|
||||||
room.toDisk();
|
|
||||||
},
|
|
||||||
onNetworkErr: () {
|
|
||||||
// no room data available
|
|
||||||
// use data from disk
|
|
||||||
(() async {
|
|
||||||
try {
|
|
||||||
final diskRoom =
|
|
||||||
await Room.fromDisk(serverTag: widget.server, id: widget.tag);
|
|
||||||
initFromRoom(diskRoom);
|
|
||||||
} catch (_) {
|
|
||||||
// no room data available
|
|
||||||
// close screen
|
|
||||||
router.pushReplacementNamed('home');
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
onServerErr: (json) {
|
|
||||||
// user not allowed to be here
|
|
||||||
// close screen
|
|
||||||
router.pushReplacementNamed('home');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
Room.listen((_) async {
|
|
||||||
// rooms changed on disk
|
|
||||||
// probably this one,
|
|
||||||
// because it is currently open
|
|
||||||
// NOTE: might be a different room
|
|
||||||
// (if a background listener is implemented at some point,
|
|
||||||
// checking if this room changed might improve performance)
|
|
||||||
try {
|
|
||||||
final room =
|
|
||||||
await Room.fromDisk(serverTag: widget.server, id: widget.tag);
|
|
||||||
|
|
||||||
initFromRoom(room);
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
showSpinner = false;
|
|
||||||
});
|
|
||||||
} catch (_) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => fetchInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final textTheme = Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.apply(displayColor: Theme.of(context).colorScheme.onSurface);
|
|
||||||
|
|
||||||
double width = MediaQuery.of(context).size.width;
|
|
||||||
double height = MediaQuery.of(context).size.height;
|
|
||||||
double smallest = min(min(width, height), 400);
|
|
||||||
|
|
||||||
return showSpinner
|
|
||||||
? Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const CircularProgressIndicator(),
|
|
||||||
Text(AppLocalizations.of(context)!.loading, style: textTheme.titleLarge),
|
|
||||||
])))
|
|
||||||
: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(AppLocalizations.of(context)!.editRoomMetadataShort),
|
|
||||||
),
|
|
||||||
body: SingleChildScrollView(
|
|
||||||
child: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints: const BoxConstraints(maxWidth: 400),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: SvgPicture.asset(
|
|
||||||
_ctrIcon.img,
|
|
||||||
width: smallest * 0.3,
|
|
||||||
height: smallest * 0.3,
|
|
||||||
),
|
|
||||||
tooltip: AppLocalizations.of(context)!.changeRoomIcon,
|
|
||||||
onPressed: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (ctx) => AlertDialog(
|
|
||||||
title: Text(
|
|
||||||
AppLocalizations.of(context)!.chooseRoomIcon),
|
|
||||||
actions: const [],
|
|
||||||
content: SizedBox(
|
|
||||||
width: smallest * 0.3 * 3,
|
|
||||||
height: smallest * 0.3 * 3,
|
|
||||||
child: GridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
children: RoomIcon.list()
|
|
||||||
.map((icon) {
|
|
||||||
return GridTile(
|
|
||||||
child: IconButton(
|
|
||||||
icon: SvgPicture
|
|
||||||
.asset(
|
|
||||||
icon.img,
|
|
||||||
width:
|
|
||||||
smallest *
|
|
||||||
0.3,
|
|
||||||
height:
|
|
||||||
smallest *
|
|
||||||
0.3,
|
|
||||||
),
|
|
||||||
tooltip:
|
|
||||||
icon.text,
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_ctrIcon =
|
|
||||||
icon;
|
|
||||||
});
|
|
||||||
context.pop();
|
|
||||||
}));
|
|
||||||
}).toList())),
|
|
||||||
));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: TextField(
|
|
||||||
enabled: false,
|
|
||||||
controller: _ctrID,
|
|
||||||
keyboardType: TextInputType.emailAddress,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
prefixIcon: const Icon(Icons.fact_check),
|
|
||||||
labelText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomIdLabel,
|
|
||||||
hintText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomIdHint,
|
|
||||||
helperText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomIdHelp,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: TextField(
|
|
||||||
controller: _ctrName,
|
|
||||||
keyboardType: TextInputType.name,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
prefixIcon: const Icon(Icons.badge),
|
|
||||||
labelText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomNameLabel,
|
|
||||||
hintText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomNameHint,
|
|
||||||
helperText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomNameHelp,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: TextField(
|
|
||||||
controller: _ctrDescription,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomDescriptionLabel,
|
|
||||||
hintText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomDescriptionHint,
|
|
||||||
helperText: AppLocalizations.of(context)!
|
|
||||||
.inputRoomDescriptionHelp,
|
|
||||||
prefixIcon: const Icon(Icons.dns),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
))))),
|
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
|
||||||
onPressed: () async {
|
|
||||||
final scaffMgr = ScaffoldMessenger.of(context);
|
|
||||||
final nav = Navigator.of(context);
|
|
||||||
final trans = AppLocalizations.of(context);
|
|
||||||
|
|
||||||
// name may not be empty
|
|
||||||
if (_ctrName.text.isEmpty) {
|
|
||||||
showSimpleSnackbar(scaffMgr,
|
|
||||||
text: trans!.errorNoRoomName, action: trans.ok);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
User user;
|
|
||||||
try {
|
|
||||||
user = await User.fromDisk();
|
|
||||||
} catch (_) {
|
|
||||||
// user data invalid
|
|
||||||
// shouldn't happen
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Room clone = room!;
|
|
||||||
clone.name = _ctrName.text;
|
|
||||||
clone.description = _ctrDescription.text;
|
|
||||||
clone.icon = _ctrIcon;
|
|
||||||
|
|
||||||
doNetworkRequest(scaffMgr,
|
|
||||||
req: ()=>postWithCreadentials(
|
|
||||||
target: user.server,
|
|
||||||
credentials: user,
|
|
||||||
path: 'changeRoomMeta',
|
|
||||||
body: {
|
|
||||||
'room': clone.id,
|
|
||||||
'server': clone.serverTag,
|
|
||||||
'title': clone.name,
|
|
||||||
'description': clone.description,
|
|
||||||
'icon': clone.icon?.type,
|
|
||||||
}),
|
|
||||||
onOK: (_) async {
|
|
||||||
// room was created
|
|
||||||
// save room
|
|
||||||
await clone.toDisk();
|
|
||||||
nav.pop();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
label: Text(AppLocalizations.of(context)!.update),
|
|
||||||
icon: const Icon(Icons.edit)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:outbag_app/backend/request.dart';
|
import 'package:outbag_app/backend/request.dart';
|
||||||
import 'package:outbag_app/backend/room.dart';
|
import 'package:outbag_app/backend/room.dart';
|
||||||
import 'package:outbag_app/backend/user.dart';
|
import 'package:outbag_app/backend/user.dart';
|
||||||
|
import 'package:outbag_app/components/room_icon_picker.dart';
|
||||||
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
||||||
import 'package:outbag_app/tools/snackbar.dart';
|
import 'package:outbag_app/tools/snackbar.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
@ -11,243 +12,325 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
class NewRoomPage extends StatefulWidget {
|
class NewRoomPage extends StatefulWidget {
|
||||||
const NewRoomPage({super.key});
|
String? server;
|
||||||
|
String? tag;
|
||||||
|
NewRoomPage({this.server, this.tag, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _NewRoomPageState();
|
State<StatefulWidget> createState() => _NewRoomPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NewRoomPageState extends State {
|
class _NewRoomPageState extends State<NewRoomPage> {
|
||||||
final TextEditingController _ctrID = TextEditingController();
|
final TextEditingController _ctrID = TextEditingController();
|
||||||
final TextEditingController _ctrName = TextEditingController();
|
final TextEditingController _ctrName = TextEditingController();
|
||||||
final TextEditingController _ctrDescription = TextEditingController();
|
final TextEditingController _ctrDescription = TextEditingController();
|
||||||
RoomVisibility _ctrVis = RoomVisibility.private;
|
RoomVisibility _ctrVis = RoomVisibility.private;
|
||||||
RoomIcon _ctrIcon = RoomIcon.other;
|
RoomIcon _ctrIcon = RoomIcon.other;
|
||||||
|
|
||||||
|
Room? room;
|
||||||
|
|
||||||
bool showSpinner = false;
|
bool showSpinner = false;
|
||||||
|
|
||||||
|
void initFromRoom(Room room) {
|
||||||
|
_ctrID.text = room.id;
|
||||||
|
_ctrName.text = room.name;
|
||||||
|
_ctrDescription.text = room.description;
|
||||||
|
_ctrIcon = room.icon!;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
this.room = room;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch room information
|
||||||
|
void fetchInfo() async {
|
||||||
|
final sm = ScaffoldMessenger.of(context);
|
||||||
|
final router = GoRouter.of(context);
|
||||||
|
final user = context.read<User>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final diskRoom =
|
||||||
|
await Room.fromDisk(serverTag: widget.server!, id: widget.tag!);
|
||||||
|
initFromRoom(diskRoom);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
doNetworkRequest(
|
||||||
|
sm,
|
||||||
|
req: () => postWithCreadentials(
|
||||||
|
path: 'getRoomInfo',
|
||||||
|
credentials: user,
|
||||||
|
target: user.server,
|
||||||
|
body: {'room': widget.tag, 'server': widget.server}),
|
||||||
|
onOK: (body) async {
|
||||||
|
final room = Room.fromJSON(body['data']);
|
||||||
|
room.toDisk();
|
||||||
|
initFromRoom(room);
|
||||||
|
},
|
||||||
|
onNetworkErr: () {
|
||||||
|
// no room data available
|
||||||
|
// use data from disk
|
||||||
|
(() async {
|
||||||
|
// no room data available
|
||||||
|
// close screen
|
||||||
|
router.pushReplacementNamed('home');
|
||||||
|
})();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
onServerErr: (json) {
|
||||||
|
// user not allowed to be here
|
||||||
|
// close screen
|
||||||
|
router.pushReplacementNamed('home');
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (isEditPage()) {
|
||||||
|
fetchInfo();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEditPage() {
|
||||||
|
return widget.server != null && widget.tag != null;
|
||||||
|
}
|
||||||
|
|
||||||
@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(min(width, height), 400);
|
double smallest = min(min(width, height), 400);
|
||||||
|
|
||||||
return showSpinner
|
return showSpinner
|
||||||
? Scaffold(
|
? Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const CircularProgressIndicator(),
|
const CircularProgressIndicator(),
|
||||||
Text(AppLocalizations.of(context)!.loading,
|
Text(AppLocalizations.of(context)!.loading,
|
||||||
style: textTheme.titleLarge),
|
style: textTheme.titleLarge),
|
||||||
])))
|
])))
|
||||||
: Scaffold(
|
: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.newRoom),
|
title: Text(isEditPage()
|
||||||
),
|
? AppLocalizations.of(context)!.editRoomMetadata
|
||||||
body: SingleChildScrollView(
|
: AppLocalizations.of(context)!.newRoom),
|
||||||
child: Center(
|
),
|
||||||
child: Padding(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(14),
|
child: Center(
|
||||||
child: ConstrainedBox(
|
child: Padding(
|
||||||
constraints: const BoxConstraints(maxWidth: 400),
|
padding: const EdgeInsets.all(14),
|
||||||
child: Column(
|
child: ConstrainedBox(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
constraints: const BoxConstraints(maxWidth: 400),
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
child: Column(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
IconButton(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
icon: SvgPicture.asset(
|
children: [
|
||||||
_ctrIcon.img,
|
IconButton(
|
||||||
width: smallest * 0.3,
|
icon: SvgPicture.asset(
|
||||||
height: smallest * 0.3,
|
_ctrIcon.img,
|
||||||
),
|
width: smallest * 0.3,
|
||||||
tooltip: AppLocalizations.of(context)!
|
height: smallest * 0.3,
|
||||||
.changeRoomIcon,
|
),
|
||||||
onPressed: () {
|
tooltip: AppLocalizations.of(context)!
|
||||||
showDialog(
|
.changeRoomIcon,
|
||||||
context: context,
|
onPressed: () {
|
||||||
builder: (ctx) => AlertDialog(
|
showDialog(
|
||||||
title: Text(
|
context: context,
|
||||||
AppLocalizations.of(context)!
|
builder: (ctx) =>
|
||||||
.chooseRoomIcon),
|
RoomIconPicker(onSelect: (icon) {
|
||||||
actions: const [],
|
setState(() {
|
||||||
content: SizedBox(
|
_ctrIcon = icon;
|
||||||
width: smallest * 0.3 * 3,
|
});
|
||||||
height: smallest * 0.3 * 3,
|
context.pop();
|
||||||
child: GridView.count(
|
}));
|
||||||
crossAxisCount: 3,
|
}),
|
||||||
children: RoomIcon.list()
|
Padding(
|
||||||
.map((icon) {
|
padding: const EdgeInsets.all(8),
|
||||||
return GridTile(
|
child: TextField(
|
||||||
child: IconButton(
|
enabled: !isEditPage(),
|
||||||
icon: SvgPicture
|
controller: _ctrID,
|
||||||
.asset(
|
keyboardType: TextInputType.emailAddress,
|
||||||
icon.img,
|
decoration: InputDecoration(
|
||||||
width:
|
prefixIcon: const Icon(Icons.fact_check),
|
||||||
smallest *
|
labelText: AppLocalizations.of(context)!
|
||||||
0.3,
|
.inputRoomIdLabel,
|
||||||
height:
|
hintText: AppLocalizations.of(context)!
|
||||||
smallest *
|
.inputRoomIdHint,
|
||||||
0.3,
|
helperText: AppLocalizations.of(context)!
|
||||||
),
|
.inputRoomIdHelp,
|
||||||
// do not display tooltip for now
|
border: const OutlineInputBorder(),
|
||||||
// as it is hard to translate
|
),
|
||||||
// and the tooltip prevented the click event,
|
),
|
||||||
// when clicked on the tooltip bar
|
),
|
||||||
// tooltip:icon.text,
|
Padding(
|
||||||
onPressed: () {
|
padding: const EdgeInsets.all(8),
|
||||||
setState(() {
|
child: TextField(
|
||||||
_ctrIcon =
|
controller: _ctrName,
|
||||||
icon;
|
keyboardType: TextInputType.name,
|
||||||
});
|
decoration: InputDecoration(
|
||||||
Navigator.of(ctx)
|
prefixIcon: const Icon(Icons.badge),
|
||||||
.pop();
|
labelText: AppLocalizations.of(context)!
|
||||||
}));
|
.inputRoomNameLabel,
|
||||||
}).toList())),
|
hintText: AppLocalizations.of(context)!
|
||||||
));
|
.inputRoomNameHint,
|
||||||
},
|
helperText: AppLocalizations.of(context)!
|
||||||
),
|
.inputRoomNameHelp,
|
||||||
Padding(
|
border: const OutlineInputBorder(),
|
||||||
padding: const EdgeInsets.all(8),
|
),
|
||||||
child: TextField(
|
),
|
||||||
controller: _ctrID,
|
),
|
||||||
keyboardType: TextInputType.emailAddress,
|
Padding(
|
||||||
decoration: InputDecoration(
|
padding: const EdgeInsets.all(8),
|
||||||
prefixIcon: const Icon(Icons.fact_check),
|
child: TextField(
|
||||||
labelText: AppLocalizations.of(context)!
|
controller: _ctrDescription,
|
||||||
.inputRoomIdLabel,
|
keyboardType: TextInputType.text,
|
||||||
hintText: AppLocalizations.of(context)!
|
decoration: InputDecoration(
|
||||||
.inputRoomIdHint,
|
labelText: AppLocalizations.of(context)!
|
||||||
helperText: AppLocalizations.of(context)!
|
.inputRoomDescriptionLabel,
|
||||||
.inputRoomIdHelp,
|
hintText: AppLocalizations.of(context)!
|
||||||
border: const OutlineInputBorder(),
|
.inputRoomDescriptionHint,
|
||||||
),
|
helperText: AppLocalizations.of(context)!
|
||||||
),
|
.inputRoomDescriptionHelp,
|
||||||
),
|
prefixIcon: const Icon(Icons.dns),
|
||||||
Padding(
|
border: const OutlineInputBorder(),
|
||||||
padding: const EdgeInsets.all(8),
|
),
|
||||||
child: TextField(
|
),
|
||||||
controller: _ctrName,
|
),
|
||||||
keyboardType: TextInputType.name,
|
...(!isEditPage())
|
||||||
decoration: InputDecoration(
|
? [
|
||||||
prefixIcon: const Icon(Icons.badge),
|
Text(
|
||||||
labelText: AppLocalizations.of(context)!
|
AppLocalizations.of(context)!
|
||||||
.inputRoomNameLabel,
|
.roomVisibilityTitle,
|
||||||
hintText: AppLocalizations.of(context)!
|
style: textTheme.labelLarge),
|
||||||
.inputRoomNameHint,
|
Text(
|
||||||
helperText: AppLocalizations.of(context)!
|
AppLocalizations.of(context)!
|
||||||
.inputRoomNameHelp,
|
.roomVisibilitySubtitle,
|
||||||
border: const OutlineInputBorder(),
|
style: textTheme.bodySmall),
|
||||||
),
|
SegmentedButton<RoomVisibility>(
|
||||||
),
|
showSelectedIcon: true,
|
||||||
),
|
multiSelectionEnabled: false,
|
||||||
Padding(
|
emptySelectionAllowed: false,
|
||||||
padding: const EdgeInsets.all(8),
|
segments:
|
||||||
child: TextField(
|
RoomVisibility.list().map((vis) {
|
||||||
controller: _ctrDescription,
|
return ButtonSegment<
|
||||||
keyboardType: TextInputType.text,
|
RoomVisibility>(
|
||||||
decoration: InputDecoration(
|
value: vis,
|
||||||
labelText: AppLocalizations.of(context)!
|
label: Text(vis.text(context)),
|
||||||
.inputRoomDescriptionLabel,
|
icon: Icon(vis.icon));
|
||||||
hintText: AppLocalizations.of(context)!
|
}).toList(),
|
||||||
.inputRoomDescriptionHint,
|
onSelectionChanged: ((vset) {
|
||||||
helperText: AppLocalizations.of(context)!
|
setState(() {
|
||||||
.inputRoomDescriptionHelp,
|
_ctrVis = vset.single;
|
||||||
prefixIcon: const Icon(Icons.dns),
|
});
|
||||||
border: const OutlineInputBorder(),
|
}),
|
||||||
),
|
selected: {_ctrVis},
|
||||||
),
|
selectedIcon: Icon(_ctrVis.icon),
|
||||||
),
|
),
|
||||||
Text(
|
]
|
||||||
AppLocalizations.of(context)!
|
: []
|
||||||
.roomVisibilityTitle,
|
],
|
||||||
style: textTheme.labelLarge),
|
))))),
|
||||||
Text(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
AppLocalizations.of(context)!
|
onPressed: () async {
|
||||||
.roomVisibilitySubtitle,
|
final scaffMgr = ScaffoldMessenger.of(context);
|
||||||
style: textTheme.bodySmall),
|
final router = GoRouter.of(context);
|
||||||
SegmentedButton<RoomVisibility>(
|
final trans = AppLocalizations.of(context);
|
||||||
showSelectedIcon: true,
|
|
||||||
multiSelectionEnabled: false,
|
|
||||||
emptySelectionAllowed: false,
|
|
||||||
segments: RoomVisibility.list().map((vis) {
|
|
||||||
return ButtonSegment<RoomVisibility>(
|
|
||||||
value: vis,
|
|
||||||
label: Text(vis.text(context)),
|
|
||||||
icon: Icon(vis.icon));
|
|
||||||
}).toList(),
|
|
||||||
onSelectionChanged: ((vset) {
|
|
||||||
setState(() {
|
|
||||||
_ctrVis = vset.single;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
selected: {_ctrVis},
|
|
||||||
selectedIcon: Icon(_ctrVis.icon),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
))))),
|
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
|
||||||
onPressed: () async {
|
|
||||||
final scaffMgr = ScaffoldMessenger.of(context);
|
|
||||||
final router = GoRouter.of(context);
|
|
||||||
final trans = AppLocalizations.of(context);
|
|
||||||
|
|
||||||
// ID should be at least three characters long
|
// name may not be empty
|
||||||
if (_ctrID.text.length < 3) {
|
if (_ctrName.text.isEmpty) {
|
||||||
showSimpleSnackbar(scaffMgr,
|
showSimpleSnackbar(scaffMgr,
|
||||||
text: _ctrID.text.isEmpty
|
text: trans!.errorNoRoomName, action: trans.ok);
|
||||||
? trans!.errorNoRoomId
|
|
||||||
: trans!.errorRoomIdLength,
|
|
||||||
action: trans.ok);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// name may not be empty
|
final user = context.read<User>();
|
||||||
if (_ctrName.text.isEmpty) {
|
|
||||||
showSimpleSnackbar(scaffMgr,
|
|
||||||
text: trans!.errorNoRoomName, action: trans.ok);
|
|
||||||
|
|
||||||
return;
|
if (isEditPage()) {
|
||||||
}
|
final nav = Navigator.of(context);
|
||||||
|
Room clone = room!;
|
||||||
|
clone.name = _ctrName.text;
|
||||||
|
clone.description = _ctrDescription.text;
|
||||||
|
clone.icon = _ctrIcon;
|
||||||
|
|
||||||
final user = context.read<User>();
|
doNetworkRequest(scaffMgr,
|
||||||
final room = Room(
|
req: () => postWithCreadentials(
|
||||||
id: _ctrID.text,
|
target: user.server,
|
||||||
serverTag: user.server.tag,
|
credentials: user,
|
||||||
name: _ctrName.text,
|
path: 'changeRoomMeta',
|
||||||
description: _ctrDescription.text,
|
body: {
|
||||||
icon: _ctrIcon,
|
'room': clone.id,
|
||||||
visibility: _ctrVis);
|
'server': clone.serverTag,
|
||||||
|
'title': clone.name,
|
||||||
|
'description': clone.description,
|
||||||
|
'icon': clone.icon?.type,
|
||||||
|
}),
|
||||||
|
onOK: (_) async {
|
||||||
|
// room was created
|
||||||
|
// save room
|
||||||
|
await clone.toDisk();
|
||||||
|
nav.pop();
|
||||||
|
});
|
||||||
|
|
||||||
doNetworkRequest(scaffMgr,
|
} else {
|
||||||
req: () => postWithCreadentials(
|
// new room specific tests & request
|
||||||
target: user.server,
|
|
||||||
credentials: user,
|
// ID should be at least three characters long
|
||||||
path: 'createRoom',
|
if (_ctrID.text.length < 3) {
|
||||||
body: {
|
showSimpleSnackbar(scaffMgr,
|
||||||
'room': room.id,
|
text: _ctrID.text.isEmpty
|
||||||
'title': room.name,
|
? trans!.errorNoRoomId
|
||||||
'description': room.description,
|
: trans!.errorRoomIdLength,
|
||||||
'icon': room.icon?.type,
|
action: trans.ok);
|
||||||
'visibility': room.visibility?.type
|
|
||||||
}),
|
return;
|
||||||
onOK: (_) async {
|
}
|
||||||
// room was created
|
|
||||||
// save room
|
final room = Room(
|
||||||
await room.toDisk();
|
id: _ctrID.text,
|
||||||
// move to home page
|
serverTag: user.server.tag,
|
||||||
router.pushReplacementNamed('home');
|
name: _ctrName.text,
|
||||||
});
|
description: _ctrDescription.text,
|
||||||
},
|
icon: _ctrIcon,
|
||||||
label: Text(AppLocalizations.of(context)!.createRoomShort),
|
visibility: _ctrVis);
|
||||||
icon: const Icon(Icons.add)),
|
|
||||||
);
|
doNetworkRequest(scaffMgr,
|
||||||
|
req: () => postWithCreadentials(
|
||||||
|
target: user.server,
|
||||||
|
credentials: user,
|
||||||
|
path: 'createRoom',
|
||||||
|
body: {
|
||||||
|
'room': room.id,
|
||||||
|
'title': room.name,
|
||||||
|
'description': room.description,
|
||||||
|
'icon': room.icon?.type,
|
||||||
|
'visibility': room.visibility?.type
|
||||||
|
}),
|
||||||
|
onOK: (_) async {
|
||||||
|
// room was created
|
||||||
|
// save room
|
||||||
|
await room.toDisk();
|
||||||
|
// move to home page
|
||||||
|
router.pushReplacementNamed('home');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
label: Text(isEditPage()
|
||||||
|
? AppLocalizations.of(context)!.editRoomMetadataShort
|
||||||
|
: AppLocalizations.of(context)!.createRoomShort),
|
||||||
|
icon: Icon(isEditPage() ? Icons.edit : Icons.add)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue