Git Product home page Git Product logo

Comments (5)

vitoMacnil avatar vitoMacnil commented on July 18, 2024 1

Ok i found the issue.
I'm using another library to get service status, and the two libraries conflicts.
Sorry for waste your time. This flutter package is very good

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

Can you see the notification?
Can you check if the service is running in background or it is stopped?

from background_locator.

vitoMacnil avatar vitoMacnil commented on July 18, 2024

Yes, I see the notification and the debug console shows me the few operations done in background, but after this operations nothing was print in the console and nothing was sent ti my server side

from background_locator.

mehdok avatar mehdok commented on July 18, 2024

Are you testing example code? if not it would be nice if you share some code.

from background_locator.

vitoMacnil avatar vitoMacnil commented on July 18, 2024

`import 'package:background_locator/background_locator.dart';
import 'package:background_locator/location_dto.dart';
import 'package:background_locator/location_settings.dart'
as BackgroundLocationSettings;
import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tracking Prototype',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Tracking Prototype Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
bool _trackingEnabled = false;

Timer timer;
bool _serviceEnabled;
PermissionStatus _permissionGranted;
Location location;
LocationData currentLocation;

static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
String deviceId;

ReceivePort port = ReceivePort();
static final _isolateName = 'LocatorIsolate';

bool _first = true, _last = false;
@OverRide
void initState() {
super.initState();

if (IsolateNameServer.lookupPortByName(_isolateName) != null) {
  IsolateNameServer.removePortNameMapping(_isolateName);
}

IsolateNameServer.registerPortWithName(port.sendPort, _isolateName);

port.listen(
  (dynamic data) async {
    await _sendMobileData(deviceId, data, null);
  },
);
location = Location();
initializeLocation();
initPlatformState();

}

@OverRide
void dispose() {
IsolateNameServer.removePortNameMapping(_isolateName);
BackgroundLocator.unRegisterLocationUpdate();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('This device has id: $deviceId'),
],
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: _trackingEnabled ? Colors.green : Colors.red,
onPressed: _enableDisableTracking,
tooltip: _trackingEnabled ? 'Disable Tracking' : 'Enable Tracking',
child: Icon(
Icons.power_settings_new,
color: Colors.white,
),
),
);
}

Future initializeLocation() async {
//check location permission and service enabled
}

Future initPlatformState() async {
await BackgroundLocator.initialize();
await BackgroundLocator.isRegisterLocationUpdate().then(
(bool isRunning) => debugPrint('Running ${isRunning.toString()}'));
}

void _enableDisableTracking() {
setState(() {
_trackingEnabled = !_trackingEnabled;
});

if (_trackingEnabled) {
  BackgroundLocator.registerLocationUpdate(
    callback,
    androidNotificationCallback: notificationCallback,
    settings: BackgroundLocationSettings.LocationSettings(
      notificationTitle: "RemoteAngel Human",
      notificationMsg: "We follow you!!!",
      accuracy: BackgroundLocationSettings.LocationAccuracy.HIGH,
      distanceFilter: 0,
      interval: 1,
      wakeLockTime: 20,
      autoStop: false,
    ),
  );
} else {
  BackgroundLocator.unRegisterLocationUpdate();
  debugPrint('Unregistered location update!!!');
  _last = true;
  Future.delayed(Duration(seconds: 1)).whenComplete(() => location
      .getLocation()
      .then((LocationData lastLocation) =>
          _sendMobileData(deviceId, null, lastLocation)));
}

}

Future _sendMobileData(String deviceId, LocationDto currentLocationDto,
LocationData currentLocationData) async {
//there is the API call to send locations to server side
debugPrint(
'Sent => $result at ${DateTime.now().toString()} with event => ${mobileDataToSend.event}');
}

static void callback(LocationDto locationDto) async {
final SendPort send = IsolateNameServer.lookupPortByName(_isolateName);
send?.send(locationDto);
}

static void notificationCallback() {
debugPrint('notificationCallback');
}
}
`
This is my code. Thanks for attention

from background_locator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.