Revolution #1
1 changed files with 48 additions and 46 deletions
|
|
@ -1,34 +1,49 @@
|
||||||
import 'package:animated_background/animated_background.dart';
|
import 'package:animated_background/animated_background.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:get_storage/get_storage.dart';
|
import 'package:tuuli_app/api_controller.dart';
|
||||||
import 'package:tuuli_app/api/api_client.dart';
|
|
||||||
|
|
||||||
class CheckupPage extends StatefulWidget {
|
|
||||||
const CheckupPage({super.key});
|
|
||||||
|
|
||||||
|
class CheckupPageController extends GetxController {
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _CheckupPageState();
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CheckupPageState extends State<CheckupPage>
|
Future<void> checkCredentials() async {
|
||||||
with TickerProviderStateMixin {
|
if (ApiController.to.token.isEmpty) {
|
||||||
@override
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
void initState() {
|
Get.offAllNamed("/login");
|
||||||
super.initState();
|
});
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
final resp =
|
||||||
|
await ApiController.to.apiClient.listTablesApiListTablesGet(
|
||||||
|
accessToken: ApiController.to.token,
|
||||||
|
);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
checkCredentials();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: AnimatedBackground(
|
body: Center(
|
||||||
behaviour: RandomParticleBehaviour(),
|
|
||||||
vsync: this,
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -37,29 +52,16 @@ class _CheckupPageState extends State<CheckupPage>
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const SizedBox.square(
|
FutureBuilder(
|
||||||
|
future: controller.checkCredentials(),
|
||||||
|
builder: (ctx, _) => const SizedBox.square(
|
||||||
dimension: 32,
|
dimension: 32,
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkCredentials() async {
|
|
||||||
final accessToken = GetStorage().read<String?>("accessToken");
|
|
||||||
if (accessToken == null) {
|
|
||||||
Get.offAllNamed("/login");
|
|
||||||
} else {
|
|
||||||
final apiClient = Get.find<ApiClient>();
|
|
||||||
(await apiClient.tablesList()).unfold((data) {
|
|
||||||
Get.offAllNamed("/home");
|
|
||||||
}, (error) async {
|
|
||||||
await GetStorage().remove("accessToken");
|
|
||||||
Get.offAllNamed("/login");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue