67 lines
1.7 KiB
Dart
67 lines
1.7 KiB
Dart
import 'package:animated_background/animated_background.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:tuuli_app/api_controller.dart';
|
|
|
|
class CheckupPageController extends GetxController {
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
}
|
|
|
|
Future<void> checkCredentials() async {
|
|
if (ApiController.to.token.isEmpty) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
Get.offAllNamed("/login");
|
|
});
|
|
} else {
|
|
try {
|
|
final resp =
|
|
await ApiController.to.apiClient.listTablesApiListTablesGet(
|
|
accessToken: ApiController.to.token,
|
|
);
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (resp.statusCode == 200) {
|
|
Get.offAllNamed("/home");
|
|
} else {
|
|
Get.offAllNamed("/login");
|
|
}
|
|
});
|
|
} catch (e) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
Get.offAllNamed("/login");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class CheckupPage extends GetView<CheckupPageController> {
|
|
const CheckupPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'Checking credentials...',
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
const SizedBox(height: 16),
|
|
FutureBuilder(
|
|
future: controller.checkCredentials(),
|
|
builder: (ctx, _) => const SizedBox.square(
|
|
dimension: 32,
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|