73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tanah_longsor_app/src/provider/maps_provider.dart';
|
|
import 'package:tanah_longsor_app/src/service/notification_api.dart';
|
|
import 'package:tanah_longsor_app/src/service/socket_io.dart';
|
|
// import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
import 'package:timezone/data/latest_all.dart' as tz;
|
|
import 'package:timezone/timezone.dart' as tz;
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
|
|
import 'src/config/routes.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
MySocketIO socket = MySocketIO();
|
|
await socket.init();
|
|
await _configureLocalTimeZone();
|
|
await dotenv.load(fileName: ".env");
|
|
HttpOverrides.global = MyHttpOverrides();
|
|
// if (defaultTargetPlatform == TargetPlatform.android) {
|
|
// AndroidGoogleMapsFlutter.useAndroidViewSurface = true;
|
|
// }
|
|
|
|
NotificationApi.init(initScheduled: true);
|
|
runApp(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (_) => MapsProvider()),
|
|
],
|
|
child: const MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
routes: MyRoutes.getRoutes(),
|
|
initialRoute: '/',
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHttpOverrides extends HttpOverrides {
|
|
@override
|
|
HttpClient createHttpClient(SecurityContext? context) {
|
|
return super.createHttpClient(context)
|
|
..badCertificateCallback =
|
|
(X509Certificate cert, String host, int port) => true;
|
|
}
|
|
}
|
|
|
|
Future<void> _configureLocalTimeZone() async {
|
|
if (kIsWeb || Platform.isLinux) {
|
|
return;
|
|
}
|
|
tz.initializeTimeZones();
|
|
final String timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
|
|
tz.setLocalLocation(tz.getLocation(timeZoneName));
|
|
}
|