jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.24k stars 1.61k forks source link

Double dependency injection while using Getx alongside audio_service in Android (flutter 3) #2369

Open christiancg opened 2 years ago

christiancg commented 2 years ago

ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.

Describe the bug Seems that using flutter 3 (stable channel), while on Android, if you use getx (latest version -> 4.6.3) alongside audio_service (latest version -> 0.18.4), when you make Get.put() or Get.lazyPut() of any service, you will see in the console that the service is created and initialized twice. This is only happening for Android, it is working correctly in iOS. This causes errors while instantiating some services that need only one instance. In my case, it is causing errors with the local database (Objectbox).

Reproduction code NOTE: THIS IS MANDATORY, IF YOUR ISSUE DOES NOT CONTAIN IT, IT WILL BE CLOSED PRELIMINARY)

example:

import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/instance_manager.dart';

void main() {
  Get.put(FakeService());
}

class FakeService extends GetxService {
}
name: getx_error
description: Showing how to reproduce interaction error between getx and audio_service
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
  sdk: ">=2.17.0 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  get: ^4.6.3
  audio_service: ^0.18.4
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
flutter:
  uses-material-design: true

To Reproduce Steps to reproduce the behavior: Run the code above on any Android device (won't happen in any iOS device)

Expected behavior Only one instance of each service should be created and initialized

Screenshots

image

Flutter Version: Flutter 3.0.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision ee4e09cce0 (9 days ago) • 2022-05-09 16:45:18 -0700 Engine • revision d1b9a6938a Tools • Dart 2.17.0 • DevTools 2.12.2

Getx Version: 4.6.3

Describe on which device you found the bug: Any android device

Minimal reproduce code Provide a minimum reproduction code for the problem (with getx 4.6.3 and audio_service 0.18.4 installed)

import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/instance_manager.dart';

void main() {
  Get.put(FakeService());
}

class FakeService extends GetxService {
}
LastxTemplar commented 1 year ago

Was this ever solved? it seems to still be happening

christiancg commented 1 year ago

I think that the issue is still happening as it was never addressed either by this library or audio service

pinktoadette commented 1 year ago

I got it to work. I have a mainBinding for all GetX and called from there. Instead of using a separate service GetxService I called using await Get.putAsync and get the AudioService