app/lib/utils/navigation_auth.dart

35 lines
959 B
Dart
Raw Normal View History

2022-05-16 06:43:42 +02:00
import 'package:universal_html/html.dart' as html;
2022-05-16 06:36:16 +02:00
import 'package:flutter/material.dart';
import 'package:nekoya_app/data/auth.dart';
import 'package:nekoya_app/screens/login.dart';
2022-05-16 06:36:16 +02:00
class NavigationAuth extends StatelessWidget {
const NavigationAuth({Key? key, required this.route}) : super(key: key);
final Widget route;
@override
Widget build(BuildContext context) {
return FutureBuilder<dynamic>(
future: checkSessionExist(),
builder: (context, snapshot) {
if (snapshot.hasData) {
var data = snapshot.data;
if (data) {
return route;
} else {
html.window.history.pushState(null, '', '/#/login');
return const Login();
}
2022-05-16 06:36:16 +02:00
} else {
return const Center(
child: CircularProgressIndicator(
color: Color(0xff8B0000),
),
);
2022-05-16 06:36:16 +02:00
}
});
2022-05-16 06:36:16 +02:00
}
}