Moved main room screen into room folder
This commit is contained in:
parent
c466a19fc9
commit
4ed46929f8
2 changed files with 25 additions and 18 deletions
|
@ -2,10 +2,9 @@ import 'package:flutter/material.dart';
|
|||
import 'package:outbag_app/backend/user.dart';
|
||||
import 'package:outbag_app/screens/room/join.dart';
|
||||
import 'package:outbag_app/screens/room/new.dart';
|
||||
import 'package:outbag_app/screens/room/shopping_list.dart';
|
||||
import './screens/home.dart';
|
||||
import './screens/welcome.dart';
|
||||
import './screens/room.dart';
|
||||
import './screens/room/main.dart';
|
||||
import './screens/auth.dart';
|
||||
import './backend/request.dart';
|
||||
import 'package:routemaster/routemaster.dart';
|
||||
|
@ -28,8 +27,7 @@ final routesLoggedIn = RouteMap(routes: {
|
|||
final server = info.pathParameters['server'] ?? "";
|
||||
final tag = info.pathParameters['tag'] ?? "";
|
||||
|
||||
return MaterialPage(
|
||||
child: RoomPage(server, tag));
|
||||
return MaterialPage(child: RoomPage(server, tag));
|
||||
},
|
||||
}, onUnknownRoute: (_) => const Redirect('/'));
|
||||
|
||||
|
@ -55,9 +53,9 @@ class _OutbagAppState extends State {
|
|||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// TODO: try to login user,
|
||||
// try to obtain user account information
|
||||
// with existing details
|
||||
|
||||
// NOTE: also functions as a way to verify ther data
|
||||
(() async {
|
||||
User credentials;
|
||||
try {
|
||||
|
@ -71,15 +69,13 @@ class _OutbagAppState extends State {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
final resp = await postUnauthorized(
|
||||
final resp = await postWithCreadentials(
|
||||
target: credentials.server,
|
||||
path: 'signin',
|
||||
body: {
|
||||
'name': credentials.username,
|
||||
'server': credentials.server.tag,
|
||||
'accountKey': credentials.password
|
||||
});
|
||||
path: 'getMyAccount',
|
||||
credentials: credentials,
|
||||
body: {});
|
||||
if (resp.res == Result.ok) {
|
||||
print(resp.body);
|
||||
setState(() {
|
||||
isAuthorized = true;
|
||||
});
|
||||
|
|
|
@ -27,9 +27,12 @@ class _RoomPageState extends State<RoomPage> {
|
|||
|
||||
// fetch room information
|
||||
void fetchInfo() async {
|
||||
bool foundData = false;
|
||||
|
||||
try {
|
||||
final diskRoom =
|
||||
await Room.fromDisk(serverTag: widget.server, id: widget.tag);
|
||||
foundData = true;
|
||||
setState(() {
|
||||
room = diskRoom;
|
||||
});
|
||||
|
@ -53,12 +56,23 @@ class _RoomPageState extends State<RoomPage> {
|
|||
if (resp.res == Result.ok) {
|
||||
final info = RoomInfo.fromJSON(resp.body['data']);
|
||||
final room = Room.fromJSON(resp.body['data']);
|
||||
|
||||
room.toDisk();
|
||||
foundData = true;
|
||||
|
||||
setState(() {
|
||||
this.info = info;
|
||||
this.room = room;
|
||||
});
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
if (!foundData) {
|
||||
// no room data available
|
||||
// TODO: close room
|
||||
// or show snackbar
|
||||
// BUG: there is currently no way of implementing this,
|
||||
// because there is no context available here
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -82,10 +96,7 @@ class _RoomPageState extends State<RoomPage> {
|
|||
// (if a background listener is implemented at some point,
|
||||
// checking if this room changed might improve performance)
|
||||
try {
|
||||
final r = await Room.fromDisk(
|
||||
serverTag: widget.server,
|
||||
id: widget.tag
|
||||
);
|
||||
final r = await Room.fromDisk(serverTag: widget.server, id: widget.tag);
|
||||
setState(() {
|
||||
room = r;
|
||||
});
|
Loading…
Reference in a new issue