rdc_flutter_sdk 0.0.22 copy "rdc_flutter_sdk: ^0.0.22" to clipboard
rdc_flutter_sdk: ^0.0.22 copied to clipboard

Flutter plugin for sending user event data to Rabbit Data Collection platform

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shop_app/controllers/example_controller.dart';
import 'package:shop_app/routes.dart';
import 'package:shop_app/screens/splash/splash_screen.dart';
import 'package:shop_app/theme.dart';
import 'package:rdc_flutter_sdk/rabbit_data.dart';
import 'package:get/get.dart';

import 'helper/storage_helper.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

   await _getPermission();

  var config = RabbitDataConfig(apiKey: 'GUawtArmlVOSlNbaTzwUMxBxlVqirqTc', dbType: DBType.realm, debugMode: true);
  // remeber for test
  config = await StorageHelper.initStorageConfig(config);
  var rabbitData = await RabbitData.initializeInstance(config);

  Get.put(rabbitData, tag: 'rabbit_data');

  // example controller
  Get.put(ExampleController());
  HttpOverrides.global = MyHttpOverrides();
  runApp(MyApp());
}

// fixed request error on Android 7
class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
  }
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: theme(),
      // home: SplashScreen(),
      // We use routeName so that we dont need to remember the name
      initialRoute: SplashScreen.routeName,
      routes: routes,
    );
  }
}

_getPermission() async {
  await Permission.location.request();
}