You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/lib/main.dart

123 lines
5.1 KiB
Dart

import 'dart:io';
import 'package:doctor_app_flutter/client/http_Overrides.dart';
3 years ago
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/provider/robot_provider.dart';
3 years ago
import 'package:doctor_app_flutter/core/service/AnalyticsService.dart';
import 'package:doctor_app_flutter/core/service/NavigationService.dart';
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/livecare_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
3 years ago
import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/unsafe_device.dart';
5 years ago
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
6 years ago
import 'package:firebase_core/firebase_core.dart';
5 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
7 years ago
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
3 years ago
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'core/service/security_service.dart';
void main() async {
6 years ago
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
HttpOverrides.global = MyHttpOverrides();
6 years ago
setupLocator();
await clearPrefsOnFirstLaunch();
7 months ago
tz.initializeTimeZones();
if (!kReleaseMode) {
await locator.get<SecurityService>().initialize();
// Set up critical threat callback to navigate to unsafe device page
locator.get<SecurityService>().setOnCriticalThreatCallback(() {
final navigationService = locator.get<NavigationService>();
final context = navigationService.navigatorKey.currentContext;
if (context != null) {
// Clear entire navigation stack and show unsafe device page
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (_) => const UnsafeDevice()),
(route) => false, // Remove all previous routes
);
debugPrint('🚨 Navigated to UnsafeDevice page - Critical threat detected');
}
});
}
6 years ago
runApp(MyApp());
}
7 years ago
//clearing all the shared pref on the inital start to avoid any profile issue
Future<void> clearPrefsOnFirstLaunch() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool isFirstLaunch = prefs.getBool('isFirstLaunch') ?? true;
await prefs.clear(); // Clear all prefs
}
7 years ago
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
AppGlobal.CONTEX = context;
return LayoutBuilder(
builder: (context, constraints) {
return OrientationBuilder(
builder: (context, orientation) {
SizeConfig().init(constraints, orientation);
return MultiProvider(
providers: [
ChangeNotifierProvider<AuthenticationViewModel>(create: (context) => AuthenticationViewModel()),
ChangeNotifierProvider<ProjectViewModel>(create: (context) => ProjectViewModel()),
ChangeNotifierProvider<LiveCareViewModel>(create: (context) => LiveCareViewModel()),
StreamProvider.value(value: RobotProvider().intStream(), initialData: RobotProvider().setValue({})),
],
child: Consumer<ProjectViewModel>(
builder: (context, projectProvider, child) => SafeArea(
top: false,
bottom: Platform.isAndroid ? true : false,
child: MaterialApp(
showSemanticsDebugger: false,
title: 'Doctors App',
locale: projectProvider.appLocal,
localizationsDelegates: [
TranslationBaseDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('ar', ''), // Arabic
const Locale('en', ''), // English
],
theme: ThemeData(
primarySwatch: Colors.grey,
primaryColor: Colors.grey,
//buttonColor: HexColor('#D02127'),
fontFamily: 'Poppins',
dividerColor: Colors.grey[350],
2 years ago
// backgroundColor: Color.fromRGBO(255, 255, 255, 1),
useMaterial3: false,
),
navigatorKey: locator<NavigationService>().navigatorKey,
navigatorObservers: [locator<AnalyticsService>().getAnalyticsObserver()],
initialRoute: INIT_ROUTE,
routes: routes,
debugShowCheckedModeBanner: false,
),
),
3 years ago
),
);
},
);
},
7 years ago
);
}
}