129 lines
4.0 KiB
Dart
129 lines
4.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_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:shared_preferences/shared_preferences.dart';
|
|
import 'package:traderscircuit/firebase_options.dart';
|
|
import 'package:scgateway_flutter_plugin/scgateway_flutter_plugin.dart';
|
|
import 'package:traderscircuit/resources/routes/route_name.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:traderscircuit/resources/routes/routes.dart';
|
|
import 'package:onesignal_flutter/onesignal_flutter.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
OneSignal.shared.setAppId("af55bb59-5ce9-4d95-92b8-e30d9ed06a73");
|
|
OneSignal.shared.promptUserForPushNotificationPermission();
|
|
OneSignal.shared
|
|
.setSubscriptionObserver((OSSubscriptionStateChanges changes) async {
|
|
await prefs.setString('playerId', changes.to.userId!);
|
|
});
|
|
// GlobalVariables globalVariables = GlobalVariables();
|
|
//token = prefs.getString('token');
|
|
// OnBoard = prefs.getBool("OnBoard");
|
|
|
|
//smallcase
|
|
ScgatewayFlutterPlugin.setConfigEnvironment(
|
|
GatewayEnvironment.PRODUCTION,
|
|
'pi-advisors',
|
|
false,
|
|
[],
|
|
);
|
|
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<ConnectivityResult> subscription;
|
|
Connectivity connectivity = Connectivity();
|
|
|
|
// @override
|
|
// void initState() {
|
|
// super.initState();
|
|
// WidgetsBinding.instance.addObserver(this);
|
|
|
|
// connectivity = Connectivity();
|
|
// checkInternet();
|
|
// subscription =
|
|
// connectivity.onConnectivityChanged.listen((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> 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();
|
|
// }
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
builder: (BuildContext context, Widget? child) => GetMaterialApp(
|
|
title: 'Traders Circuit',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
fontFamily: 'hiragino',
|
|
),
|
|
debugShowCheckedModeBanner: false,
|
|
initialRoute: RouteName.splashScreen,
|
|
getPages: AppRoutes.appRoutes(),
|
|
),
|
|
designSize: const Size(390, 844),
|
|
);
|
|
}
|
|
}
|