Files
Traders_Circuit/lib/main.dart

184 lines
6.2 KiB
Dart
Raw Permalink Normal View History

2024-03-15 19:30:17 +05:30
import 'dart:async';
import 'dart:developer';
2024-05-27 11:10:11 +05:30
import 'dart:ui';
2024-03-15 19:30:17 +05:30
import 'package:connectivity_plus/connectivity_plus.dart';
2024-06-18 10:36:24 +05:30
import 'package:firebase_core/firebase_core.dart';
2024-05-27 11:10:11 +05:30
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
2024-03-12 12:00:05 +05:30
import 'package:flutter/material.dart';
2024-03-15 19:30:17 +05:30
import 'package:flutter/services.dart';
2024-05-02 16:56:33 +05:30
import 'package:flutter_bloc/flutter_bloc.dart';
2024-06-04 15:56:01 +05:30
import 'package:flutter_branch_sdk/flutter_branch_sdk.dart';
2024-03-15 19:30:17 +05:30
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
2024-06-18 10:36:24 +05:30
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:scgateway_flutter_plugin/scgateway_flutter_plugin.dart';
2024-03-15 19:30:17 +05:30
import 'package:shared_preferences/shared_preferences.dart';
import 'package:traderscircuit/Utils/utils.dart';
import 'package:traderscircuit/firebase_options.dart';
2024-03-15 19:30:17 +05:30
import 'package:traderscircuit/resources/routes/route_name.dart';
import 'package:traderscircuit/resources/routes/routes.dart';
2024-03-12 12:00:05 +05:30
2024-05-02 16:56:33 +05:30
import 'view_model/LoginPage/Loginbloc.dart';
import 'view_model/SendOtp/sendOtpbloc.dart';
2024-03-15 19:30:17 +05:30
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
2024-05-27 11:10:11 +05:30
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;
};
2024-03-15 19:30:17 +05:30
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!);
});
2024-03-15 19:30:17 +05:30
// GlobalVariables globalVariables = GlobalVariables();
//token = prefs.getString('token');
// OnBoard = prefs.getBool("OnBoard");
2024-04-08 15:05:50 +05:30
//smallcase
ScgatewayFlutterPlugin.setConfigEnvironment(
GatewayEnvironment.PRODUCTION,
2024-06-18 10:36:24 +05:30
'traderscircuit',
2024-04-08 15:05:50 +05:30
false,
[],
);
2024-03-15 19:30:17 +05:30
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]).then((value) => runApp(MultiBlocProvider(providers: [
2024-05-02 16:56:33 +05:30
BlocProvider<CounterBloc>(
create: (context) => CounterBloc(),
),
BlocProvider<SendOtpBloc>(
create: (context) => SendOtpBloc(),
),
// Add more BlocProviders for other Blocs here if needed
], child: const MyApp())));
2024-03-12 12:00:05 +05:30
}
2024-03-15 19:30:17 +05:30
class MyApp extends StatefulWidget {
2024-03-12 12:00:05 +05:30
const MyApp({super.key});
@override
2024-03-15 19:30:17 +05:30
State<MyApp> createState() => _MyAppState();
2024-03-12 12:00:05 +05:30
}
2024-03-15 19:30:17 +05:30
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
2024-06-04 15:56:01 +05:30
StreamSubscription<Map>? streamSubscription;
StreamController<String> controllerData = StreamController<String>();
2024-03-15 19:30:17 +05:30
var _connectionStatus = ConnectivityResult.values.toString();
late StreamSubscription<ConnectivityResult> subscription;
Connectivity connectivity = Connectivity();
2024-03-12 12:00:05 +05:30
2024-04-08 15:04:07 +05:30
@override
void initState() {
super.initState();
Utils.getStoragePermission();
2024-04-08 15:04:07 +05:30
WidgetsBinding.instance.addObserver(this);
2024-06-09 14:37:53 +05:30
FlutterBranchSdk.init().then((value) => listenDynamicLinks());
2024-03-12 12:00:05 +05:30
2024-04-08 15:04:07 +05:30
connectivity = Connectivity();
checkInternet();
subscription =
connectivity.onConnectivityChanged.listen((ConnectivityResult result) {
_connectionStatus = result.toString();
if (result == ConnectivityResult.wifi ||
result == ConnectivityResult.mobile) {
setState(() {
_connectionStatus = result.toString();
2024-03-12 12:00:05 +05:30
2024-04-08 15:04:07 +05:30
Get.back(result: true);
});
} else {
setState(() {
_connectionStatus = result.toString();
Get.toNamed(RouteName.nointernet);
});
}
});
}
2024-03-12 12:00:05 +05:30
2024-06-04 15:56:01 +05:30
void listenDynamicLinks() async {
2024-06-09 14:37:53 +05:30
streamSubscription = FlutterBranchSdk.listSession().listen((data) {
2024-06-04 15:56:01 +05:30
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()}');
});
}
2024-04-08 15:04:07 +05:30
Future<void> checkInternet() async {
final connectivityResult = await (Connectivity().checkConnectivity());
2024-03-12 12:00:05 +05:30
2024-04-08 15:04:07 +05:30
if (connectivityResult == ConnectivityResult.wifi ||
connectivityResult == ConnectivityResult.mobile) {
setState(() {
_connectionStatus = connectivityResult.toString();
});
} else {
setState(() {
_connectionStatus = connectivityResult.toString();
print(_connectionStatus.toString());
Get.toNamed(RouteName.nointernet);
2024-03-12 12:00:05 +05:30
2024-04-08 15:04:07 +05:30
// Navigator.pushReplacementNamed(context, "/noInternet");
});
}
}
2024-03-15 19:30:17 +05:30
2024-04-08 15:04:07 +05:30
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
2024-03-15 19:30:17 +05:30
2024-04-08 15:04:07 +05:30
subscription.cancel();
}
2024-03-12 12:00:05 +05:30
2024-03-15 19:30:17 +05:30
// This widget is the root of your application.
2024-03-12 12:00:05 +05:30
@override
Widget build(BuildContext context) {
2024-03-15 19:30:17 +05:30
return ScreenUtilInit(
builder: (BuildContext context, Widget? child) => GetMaterialApp(
2024-04-04 11:45:15 +05:30
title: 'Traders Circuit',
2024-03-15 19:30:17 +05:30
theme: ThemeData(
primarySwatch: Colors.blue,
2024-04-04 11:45:15 +05:30
fontFamily: 'hiragino',
2024-03-12 12:00:05 +05:30
),
2024-03-15 19:30:17 +05:30
debugShowCheckedModeBanner: false,
initialRoute: RouteName.splashScreen,
2024-03-15 19:30:17 +05:30
getPages: AppRoutes.appRoutes(),
2024-03-12 12:00:05 +05:30
),
2024-03-15 19:30:17 +05:30
designSize: const Size(390, 844),
2024-03-12 12:00:05 +05:30
);
}
}