mirror of
https://github.com/go-vikunja/app
synced 2024-05-29 00:36:49 +00:00
fixed logout
This commit is contained in:
parent
b917b27a83
commit
6176af2acb
|
@ -13,7 +13,6 @@ import '../main.dart';
|
|||
|
||||
class Client {
|
||||
GlobalKey<ScaffoldMessengerState>? global_scaffold_key;
|
||||
GlobalKey<NavigatorState>? navigator_key;
|
||||
final JsonDecoder _decoder = new JsonDecoder();
|
||||
final JsonEncoder _encoder = new JsonEncoder();
|
||||
String _token = '';
|
||||
|
@ -32,7 +31,7 @@ class Client {
|
|||
return otherClient._token == _token;
|
||||
}
|
||||
|
||||
Client(this.global_scaffold_key, this.navigator_key,
|
||||
Client(this.global_scaffold_key,
|
||||
{String? token, String? base, bool authenticated = false}) {
|
||||
configure(token: token, base: base, authenticated: authenticated);
|
||||
}
|
||||
|
@ -131,8 +130,6 @@ class Client {
|
|||
|
||||
|
||||
Error? _handleResponseErrors(http.Response response) {
|
||||
if(response.statusCode == 412)
|
||||
return Error("Login failed!");
|
||||
if (response.statusCode < 200 ||
|
||||
response.statusCode >= 400) {
|
||||
Map<String, dynamic> error;
|
||||
|
@ -146,7 +143,7 @@ class Client {
|
|||
label: ("Details"),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: navigator_key!.currentContext!,
|
||||
context: globalNavigatorKey.currentContext!,
|
||||
builder: (BuildContext context) =>
|
||||
AlertDialog(
|
||||
title: Text("Error ${response.statusCode}"),
|
||||
|
|
|
@ -20,6 +20,8 @@ import 'package:vikunja_app/service/services.dart';
|
|||
import 'package:timezone/data/latest_all.dart' as tz;
|
||||
import 'package:workmanager/workmanager.dart';
|
||||
|
||||
import 'main.dart';
|
||||
|
||||
|
||||
class VikunjaGlobal extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
@ -32,7 +34,7 @@ class VikunjaGlobal extends StatefulWidget {
|
|||
|
||||
static VikunjaGlobalState of(BuildContext context) {
|
||||
var widget =
|
||||
context.dependOnInheritedWidgetOfExactType<_VikunjaGlobalInherited>();
|
||||
context.dependOnInheritedWidgetOfExactType<VikunjaGlobalInherited>();
|
||||
return widget!.data;
|
||||
}
|
||||
}
|
||||
|
@ -52,9 +54,7 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
|
||||
Client get client => _client;
|
||||
|
||||
final snackbarKey = GlobalKey<ScaffoldMessengerState>();
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
GlobalKey<ScaffoldMessengerState> get snackbarKey => globalSnackbarKey;
|
||||
|
||||
UserManager get userManager => new UserManager(_storage);
|
||||
|
||||
|
@ -105,7 +105,7 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_client = Client(snackbarKey, navigatorKey);
|
||||
_client = Client(snackbarKey);
|
||||
settingsManager.getIgnoreCertificates().then((value) => client.reload_ignore_certs(value == "1"));
|
||||
_newUserService = UserAPIService(client);
|
||||
_loadCurrentUser();
|
||||
|
@ -151,7 +151,6 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
var userId = await _storage.read(key: "currentUser");
|
||||
await _storage.delete(key: userId!); //delete token
|
||||
await _storage.delete(key: "${userId}_base");
|
||||
Navigator.pop(context);
|
||||
setState(() {
|
||||
client.reset();
|
||||
_currentUser = null;
|
||||
|
@ -217,7 +216,7 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
if(client.authenticated) {
|
||||
notifications.scheduleDueNotifications(taskService);
|
||||
}
|
||||
return new _VikunjaGlobalInherited(
|
||||
return new VikunjaGlobalInherited(
|
||||
data: this,
|
||||
key: UniqueKey(),
|
||||
child: !client.authenticated ? widget.login : widget.child,
|
||||
|
@ -225,14 +224,14 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
|||
}
|
||||
}
|
||||
|
||||
class _VikunjaGlobalInherited extends InheritedWidget {
|
||||
class VikunjaGlobalInherited extends InheritedWidget {
|
||||
final VikunjaGlobalState data;
|
||||
|
||||
_VikunjaGlobalInherited({Key? key, required this.data, required Widget child})
|
||||
VikunjaGlobalInherited({Key? key, required this.data, required Widget child})
|
||||
: super(key: key, child: child);
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(_VikunjaGlobalInherited oldWidget) {
|
||||
bool updateShouldNotify(VikunjaGlobalInherited oldWidget) {
|
||||
return (data.currentUser != null &&
|
||||
data.currentUser!.id != oldWidget.data.currentUser!.id) ||
|
||||
data.client != oldWidget.data.client;
|
||||
|
|
|
@ -34,7 +34,7 @@ void callbackDispatcher() {
|
|||
Workmanager().executeTask((task, inputData) {
|
||||
print("Native called background task: $task"); //simpleTask will be emitted here.
|
||||
if (task == "update-tasks" && inputData != null) {
|
||||
Client client = Client(null, null,
|
||||
Client client = Client(null,
|
||||
token: inputData["client_token"],
|
||||
base: inputData["client_base"],
|
||||
authenticated: true);
|
||||
|
@ -58,6 +58,8 @@ void callbackDispatcher() {
|
|||
}
|
||||
});
|
||||
}
|
||||
final globalSnackbarKey = GlobalKey<ScaffoldMessengerState>();
|
||||
final globalNavigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
@ -71,6 +73,7 @@ void main() async {
|
|||
child: new VikunjaApp(
|
||||
home: HomePage(),
|
||||
key: UniqueKey(),
|
||||
navkey: globalNavigatorKey,
|
||||
),
|
||||
login: new VikunjaApp(
|
||||
home: LoginPage(),
|
||||
|
@ -80,8 +83,9 @@ void main() async {
|
|||
|
||||
class VikunjaApp extends StatelessWidget {
|
||||
final Widget home;
|
||||
final GlobalKey<NavigatorState>? navkey;
|
||||
|
||||
const VikunjaApp({Key? key, required this.home}) : super(key: key);
|
||||
const VikunjaApp({Key? key, required this.home, this.navkey}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -89,7 +93,8 @@ class VikunjaApp extends StatelessWidget {
|
|||
title: 'Vikunja',
|
||||
theme: buildVikunjaTheme(),
|
||||
darkTheme: buildVikunjaDarkTheme(),
|
||||
scaffoldMessengerKey: VikunjaGlobal.of(context).snackbarKey,
|
||||
scaffoldMessengerKey: globalSnackbarKey,
|
||||
navigatorKey: navkey,
|
||||
// <= this
|
||||
home: this.home,
|
||||
);
|
||||
|
|
|
@ -25,17 +25,6 @@ class HomePageState extends State<HomePage> {
|
|||
int _selectedDrawerIndex = 0, _previousDrawerIndex = 0;
|
||||
Widget? drawerItem;
|
||||
|
||||
Widget _userDetailsWidget(BuildContext context) {
|
||||
return ListView(padding: EdgeInsets.zero, children: <Widget>[
|
||||
ListTile(
|
||||
title: Text('Logout'),
|
||||
leading: Icon(Icons.exit_to_app),
|
||||
onTap: () {
|
||||
VikunjaGlobal.of(context).logoutUser(context);
|
||||
},
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
List<Widget> widgets = [
|
||||
ChangeNotifierProvider<ListProvider>(
|
||||
|
|
|
@ -167,9 +167,7 @@ class SettingsPageState extends State<SettingsPage> {
|
|||
: ""),
|
||||
Divider(),
|
||||
TextButton(
|
||||
onPressed: () => setState(() {
|
||||
VikunjaGlobal.of(context).logoutUser(context);
|
||||
}),
|
||||
onPressed: () => VikunjaGlobal.of(context).logoutUser(context),
|
||||
child: Text("Logout")),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -177,7 +177,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||
_deleteTask(BuildContext context) async {
|
||||
await VikunjaGlobal.of(context).taskService.delete(widget.task.id).then(
|
||||
(value) {
|
||||
Navigator.pop(context);
|
||||
navigatorKey.currentState?.pop(context);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -229,16 +229,16 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||
child: Text('Dismiss'),
|
||||
onPressed: () {
|
||||
log("Dismiss");
|
||||
Navigator.pop(context);
|
||||
navigatorKey.currentState?.pop(context);
|
||||
// make sure the list is refreshed
|
||||
Navigator.pop(context);
|
||||
navigatorKey.currentState?.pop(context);
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Cancel'),
|
||||
onPressed: () {
|
||||
log("cancel");
|
||||
Navigator.pop(context);
|
||||
navigatorKey.currentState?.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue
Block a user