72 lines
1.7 KiB
Dart
72 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'firebase_options.dart';
|
|
import 'page_auth/login.dart';
|
|
import 'page2/Controlsystem.dart';
|
|
import 'auth/auth_service.dart';
|
|
|
|
Future<void> firebaseMessagingBackgroundHandler(
|
|
RemoteMessage message,
|
|
) async {
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
|
|
debugPrint(
|
|
'Background Message: ${message.notification?.title}',
|
|
);
|
|
}
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
|
|
FirebaseMessaging.onBackgroundMessage(
|
|
firebaseMessagingBackgroundHandler,
|
|
);
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: 'Monitoring Amoniak',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: FutureBuilder<bool>(
|
|
future: AuthService.isLoggedIn(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const LoadingScreen();
|
|
}
|
|
return snapshot.data == true ? const ControlSystem() : const Login();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class LoadingScreen extends StatelessWidget {
|
|
const LoadingScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(
|
|
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFF2476C7)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|