Closed Bubbleability closed 2 years ago
Read the API docs Config.debug
. Those notifications are there to assist you during development so you can see (and hear) the plugin working while out field-testing, so you don't have to run back to your office to determine if the plugin worked or not.
Your Environment
flutter doctor
): Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.63.2) [✓] Connected device (2 available)• No issues found!
void backgroundGeolocationHeadlessTask(bg.HeadlessEvent headlessEvent) async { print('📬 --> $headlessEvent');
switch (headlessEvent.name) { case bg.Event.BOOT: bg.State state = await bg.BackgroundGeolocation.state; print("📬 didDeviceReboot: ${state.didDeviceReboot}"); break; case bg.Event.TERMINATE: try { bg.Location location = await bg.BackgroundGeolocation.getCurrentPosition(samples: 1); print("[getCurrentPosition] Headless: $location"); } catch (error) { print("[getCurrentPosition] Headless ERROR: $error"); } break; case bg.Event.HEARTBEAT:
} }
void backgroundFetchHeadlessTask(HeadlessTask task) async { String taskId = task.taskId;
// Is this a background_fetch timeout event? If so, simply #finish and bail-out. if (task.timeout) { print("[BackgroundFetch] HeadlessTask TIMEOUT: $taskId"); BackgroundFetch.finish(taskId); return; }
print("[BackgroundFetch] HeadlessTask: $taskId");
SharedPreferences prefs = await SharedPreferences.getInstance(); int count = 0; if (prefs.get("fetch-count") != null) { count = prefs.getInt("fetch-count"); } prefs.setInt("fetch-count", ++count); print('[BackgroundFetch] count: $count');
BackgroundFetch.finish(taskId); }
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp();
SharedPreferences.getInstance().then((SharedPreferences prefs) { String appName = prefs.getString("app");
}); TransistorAuth.registerErrorHandler();
/// Register BackgroundGeolocation headless-task. bg.BackgroundGeolocation.registerHeadlessTask( backgroundGeolocationHeadlessTask);
/// Register BackgroundFetch headless-task. BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, );
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true);
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { runApp(new MyApp()); });
// called in initState of homescreen
Future _initPlatformState() async {
SharedPreferences prefs = await _prefs;
String orgname = prefs.getString("orgname");
String username = prefs.getString("username");
} }
Future _initPlatformState() async {
SharedPreferences prefs = await _prefs;
String orgname = prefs.getString("orgname");
String username = prefs.getString("username");
} }