Adds the Flutter inventory app source, cleaned up for a shared repo: generic package name, no hardcoded ERP endpoints (moved to gitignored local config), no dead auth code, no debug logging of session data.
38 lines
1.2 KiB
Dart
38 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:inventory_app/views/splash_screen.dart';
|
|
import 'package:inventory_app/my_app.dart';
|
|
import 'package:inventory_app/views/login_view.dart';
|
|
import 'package:inventory_app/service/axelor_client.dart';
|
|
|
|
class Auth extends StatelessWidget {
|
|
const Auth({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final box = GetStorage();
|
|
String? sessionId = box.read('sessionId');
|
|
|
|
if (sessionId == null) {
|
|
return const LoginView();
|
|
}
|
|
|
|
// Session exists on disk — validate it with the server before granting access
|
|
return FutureBuilder<bool>(
|
|
future: AxelorClient.create().then((client) => client.isSessionValid()),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const SplashScreen();
|
|
} else if (snapshot.hasError || !(snapshot.data ?? false)) {
|
|
// Session is expired or invalid — clear it and force re-login
|
|
box.remove('sessionId');
|
|
box.remove('username');
|
|
return const LoginView();
|
|
} else {
|
|
return MyApp();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|