flutter_combainsdk 0.4.17
flutter_combainsdk: ^0.4.17 copied to clipboard
A Flutter wrapper for the Combain AI Navigation SDK.
example/lib/main.dart
import 'package:flutter_combain_sdk_example/comabin_logger.dart';
import 'package:flutter_combain_sdk_example/components/map/map.dart';
import 'package:flutter_combain_sdk_example/models/api.dart';
import 'package:flutter_combain_sdk_example/models/log_store.dart';
import 'package:flutter_combain_sdk_example/models/preferences.dart';
import 'package:flutter_combain_sdk_example/models/route_generator.dart';
import 'package:flutter_combain_sdk_example/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_combainsdk/flutter_combain_sdk.dart';
import 'package:flutter_combainsdk/messages.g.dart';
import 'package:get_it/get_it.dart';
import 'package:logger/logger.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
final getIt = GetIt.instance;
late FlutterCombainSDK aiIndoorNavigationSDK;
class LogOutputWrapper extends ConsoleOutput {
SentryLevel _toSentryLevel(Level level) {
switch (level) {
case Level.info:
return SentryLevel.info;
case Level.warning:
return SentryLevel.warning;
case Level.error:
return SentryLevel.error;
case Level.fatal:
return SentryLevel.fatal;
default:
return SentryLevel.debug;
}
}
@override
void output(OutputEvent event) {
if (event.level == Level.error) {
Sentry.captureMessage(event.lines.join("\n"), level: SentryLevel.error);
} else {
Sentry.addBreadcrumb(
Breadcrumb(
level: _toSentryLevel(event.level),
message: event.lines.join("\n"),
),
);
}
super.output(event);
}
}
var logger = Logger(
//filter: TestLogFilter(),
printer: PrettyPrinter(
dateTimeFormat: DateTimeFormat.onlyTimeAndSinceStart,
methodCount: 4,
errorMethodCount: 4,
),
output: LogOutputWrapper(),
);
final combainLogger = CustomCombainLogger(logger: logger);
Future setupGetIt() async {
final prefs = await Preferences.create();
GetIt.I.registerSingleton<Preferences>(prefs);
GetIt.I.registerLazySingleton(() => API());
getIt.registerLazySingleton<Logger>(() => logger);
getIt.registerLazySingleton(() => const MapView());
getIt.registerLazySingleton(() => LogStore());
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await setupGetIt();
await SentryFlutter.init((options) {
options.dsn =
'https://7d3eca5d39954acb6f63659b9be82d70@o4506755576430592.ingest.us.sentry.io/4507612717252608';
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0;
// The sampling rate for profiling is relative to tracesSampleRate
// Setting to 1.0 will profile 100% of sampled transactions:
options.profilesSampleRate = 1.0;
}, appRunner: () => runApp(const MyApp()));
}
Future<void> initIndoorNavigationSDK() async {
final prefs = GetIt.I<Preferences>();
final scanningConfig = prefs.scanningConfig;
var config = CombainSDKConfig(
apiKey: prefs.apiKey!,
settingsKey: prefs.apiKey!,
appInfo: FlutterAppInfo(
packageName: 'com.combain.flutter_example',
versionName: '1.0.0',
versionCode: 1,
),
locationProvider: FlutterLocationProvider.aiNavigation,
routingConfig: FlutterRoutingConfig(
routableNodesOptions: FlutterRoutableNodesOptions.allExceptDefaultName,
),
syncingInterval: FlutterSyncingInterval(
type: FlutterSyncingIntervalType.interval,
intervalMilliseconds: 60 * 1000 * 60),
wifiEnabled: scanningConfig.wifiScanningEnabled,
bluetoothEnabled: scanningConfig.bleScanningEnabled,
beaconUUIDs: ["E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"]);
logger.i("Creating SDK with config: $config.syncingInterval");
// Step 1: Create the SDK instance with constructor config
aiIndoorNavigationSDK = await FlutterCombainSDK.create(
constructorConfig: ConstructorConfig(
debug: true,
logger: combainLogger,
alsoNativeLogs: true,
),
);
// Step 2: Initialize the SDK with the config
await aiIndoorNavigationSDK.initializeSDK(config);
getIt.registerSingleton<FlutterCombainSDK>(aiIndoorNavigationSDK);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Your App Name',
theme: AppTheme.getTheme(),
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}