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