168 lines
5.1 KiB
Dart
168 lines
5.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:regroup/Utils/dialogs.dart';
|
|
import 'package:regroup/resources/routes/route_name.dart';
|
|
import 'package:regroup/resources/routes/routes.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
// void main() {
|
|
// runApp(const MyApp());
|
|
// }
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// GlobalVariables globalVariables = GlobalVariables();
|
|
|
|
// token = prefs.getString('token');
|
|
// await Firebase.initializeApp(
|
|
// options: DefaultFirebaseOptions.currentPlatform,
|
|
// );
|
|
// FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
|
|
// PlatformDispatcher.instance.onError = (error, stack) {
|
|
// FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
|
// return true;
|
|
// };
|
|
// OnBoard = prefs.getBool("OnBoard");
|
|
SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.portraitUp,
|
|
]).then((value) => runApp(const MyApp()));
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
var _connectionStatus = ConnectivityResult.values.toString();
|
|
late StreamSubscription<List<ConnectivityResult>> subscription;
|
|
Connectivity connectivity = Connectivity();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
connectivity = Connectivity();
|
|
checkInternet();
|
|
// if (Platform.isAndroid) {
|
|
// _getStoragePermission();
|
|
// }
|
|
// _getStoragePermission();
|
|
subscription = connectivity.onConnectivityChanged
|
|
.listen((List<ConnectivityResult> result) {
|
|
_connectionStatus = result.toString();
|
|
if (result == ConnectivityResult.wifi ||
|
|
result == ConnectivityResult.mobile) {
|
|
setState(() {
|
|
_connectionStatus = result.toString();
|
|
|
|
Get.back(result: true);
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_connectionStatus = result.toString();
|
|
Get.toNamed(RouteName.nointernet);
|
|
});
|
|
}
|
|
});
|
|
// print(_connectionStatus);
|
|
}
|
|
|
|
Future<void> _getStoragePermission() async {
|
|
DeviceInfoPlugin plugin = DeviceInfoPlugin();
|
|
AndroidDeviceInfo android = await plugin.androidInfo;
|
|
if (android.version.sdkInt < 33) {
|
|
if (await Permission.storage.request().isGranted) {
|
|
// setState(() {
|
|
// permissionGranted = true;
|
|
// });
|
|
} else if (await Permission.storage.request().isPermanentlyDenied) {
|
|
await openAppSettings();
|
|
await utils.showToast("Permission denied.");
|
|
}
|
|
// else if (await Permission.audio.request().isDenied) {
|
|
// // setState(() {
|
|
// // permissionGranted = false;
|
|
// // });
|
|
// }
|
|
} else {
|
|
if (await Permission.photos.request().isGranted) {
|
|
// await utils.showToast("Permission granted.");
|
|
// setState(() {
|
|
// permissionGranted = true;
|
|
// });
|
|
} else if (await Permission.photos.request().isPermanentlyDenied) {
|
|
await openAppSettings();
|
|
await utils.showToast("Permission denied.");
|
|
} else if (await Permission.photos.request().isDenied) {
|
|
await openAppSettings();
|
|
await utils.showToast("Permission denied.");
|
|
// setState(() {
|
|
// permissionGranted = false;
|
|
// });
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> checkInternet() async {
|
|
final connectivityResult = await (Connectivity().checkConnectivity());
|
|
|
|
if (connectivityResult == ConnectivityResult.wifi ||
|
|
connectivityResult == ConnectivityResult.mobile) {
|
|
setState(() {
|
|
_connectionStatus = connectivityResult.toString();
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_connectionStatus = connectivityResult.toString();
|
|
print(_connectionStatus.toString());
|
|
Get.toNamed(RouteName.nointernet);
|
|
|
|
// Navigator.pushReplacementNamed(context, "/noInternet");
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
subscription.cancel();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return
|
|
ScreenUtilInit(
|
|
builder: (BuildContext context, Widget? child) => GetMaterialApp(
|
|
title: 'Regroup',
|
|
theme: ThemeData(
|
|
primarySwatch:
|
|
// createPrimarySwatch(Color(0xFF737373)),
|
|
Colors.grey,
|
|
fontFamily: 'Cambria',
|
|
),
|
|
debugShowCheckedModeBanner: false,
|
|
initialRoute: RouteName.splashScreen,
|
|
|
|
//initialRoute: RouteName.mainScreen,
|
|
getPages: AppRoutes.appRoutes(),
|
|
),
|
|
designSize: const Size(390, 844),
|
|
);
|
|
}
|
|
}
|
|
|