From 08b8e2fef498020f1625d615e75a3c574dfb90b4 Mon Sep 17 00:00:00 2001 From: Moe Date: Mon, 16 May 2022 11:36:16 +0700 Subject: [PATCH] Add NavigationAuth --- lib/utils/navigation_auth.dart | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/utils/navigation_auth.dart diff --git a/lib/utils/navigation_auth.dart b/lib/utils/navigation_auth.dart new file mode 100644 index 0000000..d8bf2b9 --- /dev/null +++ b/lib/utils/navigation_auth.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; + +import 'package:nekoya_flutter/data/auth.dart'; +import 'package:nekoya_flutter/screens/login.dart'; + +class NavigationAuth extends StatelessWidget { + const NavigationAuth({Key? key, required this.route}) : super(key: key); + + final Widget route; + + @override + Widget build(BuildContext context) { + + return FutureBuilder( + future: checkSessionExist(), + builder: (context, snapshot) { + if (snapshot.hasData) { + var data = snapshot.data; + if (data) { + return route; + } else { + return const Login(); + } + } else { + return const Center( + child: CircularProgressIndicator( + color: Color(0xff8B0000), + ), + ); + } + } + ); + } +} \ No newline at end of file