Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huawei location package throwing error while build web #380

Open
alamen-pgooja opened this issue Jul 19, 2024 · 1 comment
Open

huawei location package throwing error while build web #380

alamen-pgooja opened this issue Jul 19, 2024 · 1 comment

Comments

@alamen-pgooja
Copy link

Description
I'm using the same codebase for mobile and web, and I use the Huawei location library. When I run flutter build web, the build crashes during the compilation of the library.
Log:

Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
../../.pub-cache/hosted/pub.dev/huawei_location-6.12.0+302/lib/src/location/location_request.dart:120:23:
Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
    _expirationTime = 9223372036854775807;

Expected Behavior
The build should compile normally.

Current Behavior
The build fails during compilation.

Logs

Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
../../.pub-cache/hosted/pub.dev/huawei_location-6.12.0+302/lib/src/location/location_request.dart:120:23:
Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
    _expirationTime = 9223372036854775807;
                      ^^^^^^^^^^^^^^^^^^^

Environment

  • Platform: flutter
  • Kit: huawei_location
  • Kit Version huawei_location : 6.12.0+302
  • OS Version WEB
@megaacheyounes
Copy link

Huawei Flutter Location Library depend on Huawei Android Location SDK, it is intended to be used with Android only and it is not compatible with web applications, as a workaround, consider using conditional import to exclude Huawei Location library from your web build:

this code was not tested

create empty implementation for Web platform

example path: lib/stubs/huawei_location_stub.dart:

class FusedLocationProviderClient {
  // Define the methods and properties used from Huawei Location library.

  Future<void> getLastLocation() async {
    // No implementation for web.
  }
  // Add other methods as needed.
}

use conditional import to exclude real FusedLocationProviderClient for web

example path: lib/location_service_selector.dart:

export 'package:huawei_location/huawei_location.dart'
    if (dart.library.html) 'stubs/huawei_location_stub.dart';

update your code to import from location service selector

import 'package:flutter/material.dart';
import 'location_service_selector.dart';

class LocationScreen extends StatelessWidget {
  LocationScreen({Key? key}) : super(key: key);

  final FusedLocationProviderClient _locationService =
      FusedLocationProviderClient();

  getLastLocation() async {
    final Location location = await _locationService.getLastLocation();
    // ...
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(...);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants