184 lines
6.2 KiB
Dart
184 lines
6.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:developer';
|
|
import 'dart:ui';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_branch_sdk/flutter_branch_sdk.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:traderscircuit/Utils/utils.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';
|
|
|
|
import 'view_model/LoginPage/Loginbloc.dart';
|
|
import 'view_model/SendOtp/sendOtpbloc.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
|
|
FlutterError.onError = (errorDetails) {
|
|
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
|
|
};
|
|
// Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
|
|
PlatformDispatcher.instance.onError = (error, stack) {
|
|
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
|
return true;
|
|
};
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
OneSignal.shared.setAppId("af55bb59-5ce9-4d95-92b8-e30d9ed06a73");
|
|
OneSignal.shared.promptUserForPushNotificationPermission();
|
|
OneSignal.shared
|
|
.setSubscriptionObserver((OSSubscriptionStateChanges changes) async {
|
|
log(changes.to.userId!.toString());
|
|
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(MultiBlocProvider(providers: [
|
|
BlocProvider<CounterBloc>(
|
|
create: (context) => CounterBloc(),
|
|
),
|
|
BlocProvider<SendOtpBloc>(
|
|
create: (context) => SendOtpBloc(),
|
|
),
|
|
// Add more BlocProviders for other Blocs here if needed
|
|
], child: const MyApp())));
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
StreamSubscription<Map>? streamSubscription;
|
|
StreamController<String> controllerData = StreamController<String>();
|
|
var _connectionStatus = ConnectivityResult.values.toString();
|
|
late StreamSubscription<ConnectivityResult> subscription;
|
|
Connectivity connectivity = Connectivity();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Utils.getStoragePermission();
|
|
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);
|
|
}
|
|
|
|
void listenDynamicLinks() async {
|
|
streamSubscription = FlutterBranchSdk.initSession().listen((data) {
|
|
print('listenDynamicLinks - DeepLink Data: $data');
|
|
controllerData.sink.add((data.toString()));
|
|
if (data.containsKey('+clicked_branch_link') &&
|
|
data['+clicked_branch_link'] == true) {
|
|
debugPrint(
|
|
'------------------------------------Link clicked----------------------------------------------');
|
|
// debugPrint('Custom string: ${data['custom_string']}');
|
|
debugPrint('Custom number: ${data['custom_number']}');
|
|
debugPrint("var type is ${data['custom_number'].runtimeType}");
|
|
debugPrint(
|
|
'------------------------------------------------------------------------------------------------');
|
|
// showSnackBar(
|
|
// message: 'Link clicked: Custom string - ${data['custom_string']}',
|
|
// duration: 10);
|
|
// Get.to(() =>
|
|
// SvpMain(fromHome: false, index: int.parse(data['custom_number'])));
|
|
}
|
|
}, onError: (error) {
|
|
print('InitSesseion error: ${error.toString()}');
|
|
});
|
|
}
|
|
|
|
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),
|
|
);
|
|
}
|
|
}
|