Unable to Initialize Firebase in my application - Flutter - flutter

I'm trying to integrate the Firebase registration in my application by using the version firebase_auth: ^3.3.6 & firebase_core: ^1.11.0, upon using this in pubspec and initializing in the app as final _auth = FirebaseAuth.instance;
Do have initialized firebase in main as
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
I'm getting an error stating as
/C:/src/flutter2.8/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.2.0/lib/src/method_channel/utils/exception.dart:14:11: Error: Member not found: 'Error.throwWithStackTrace'. Error.throwWithStackTrace(exception, stackTrace);

Try to upgrade your flutter using,
flutter upgrade
If this is not working than try using lower version of firebase_auth:2.0.0
I found this Link

Related

Firebase crashlytics is not reporting anything on Flutter

I've initialized and configured Firebase for my Flutter project using this documentation and the instructions given by the Firebase Console. After that, I followed this crashlytics documentation for adding crashlytics to my app. But no matter what I've tried, I couldn't see any reports on the Firebase console. Still seeing this;
My main function looks like this:
Future main() async {
runZonedGuarded(
() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
runApp(const App());
},
(error, stack) async {
await FirebaseCrashlytics.instance.recordError(error, stack);
},
);
}
I've tried to;
crash my app using FirebaseCrashlytics.instance.crash()
throw an exception and record it by the onError callback of the runZonedGuarded
manually record an exception using FirebaseCrashlytics.recordError(error, stack)
setting fatal: true or using FirebaseCrashlytics.instance.recordFlutterFatalError
Is there something that I'm missing? I'm really stuck at this point.

Cannot upload files to Firebase Storage using Flutter in Debug mode

Hi I'm having trouble testing uploading files to Firebase Storage with Flutter using an emulator in Android Studio. I keep getting this error even though I followed the documentation: https://firebase.google.com/docs/app-check/flutter/default-providers. I also followed the one for debug mode: https://firebase.google.com/docs/app-check/flutter/debug-provider.
Error getting App Check token; using placeholder token instead. Error:
com.google.firebase.FirebaseException: 7:
Here is my MainActivity.kt
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
FirebaseApp.initializeApp(this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
super.onCreate(savedInstanceState)
}
}
main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp(
name: 'XXX',
options: DefaultFirebaseOptions.currentPlatform,
);
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
);
}
runApp(const MyApp());
}
I've read a lot of answers to this question but none work. I expect to see this line in my logs but I don't see it
D DebugAppCheckProvider: Enter this debug secret into the allow list
in the Firebase Console for your project:
123a4567-b89c-12d3-e456-789012345678
Please help. Thank you!

HiveDB in macos build flutter

I have a flutter app that uses hiveDB, its working perfectly on iOS device and simulator, but when building it on macOS, the following error pops.
Unhandled Exception: HiveError: Cannot read, unknown typeId: 32. Did you forget to register an adapter?
This is my main method:
main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
Hive.registerAdapter(PriceAdapter());
Hive.registerAdapter(AmountAdapter());
Hive.registerAdapter(CustomerAdapter());
Hive.registerAdapter(ProductAdapter());
Hive.registerAdapter(FactorAdapter());
await Hive.openBox<Product>(TableName.PRODUCT);
await Hive.openBox<Factor>(TableName.FACTOR);
runApp(MyApp());
}

The method getImage isn't defined

I am using image_picker 0.6.7+17 library in order to take an image using the phone camera.
I am using an android device and not an ios device.
A problem
It seems like that getImage method is not defined, I took this exact code from the docs:
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
}
I am getting this error:
lib/pickers/image_picker.dart:17:37: Error: The method 'getImage' isn't defined for the class
'ImagePicker'.
- 'ImagePicker' is from 'package:chat_app/pickers/image_picker.dart'
('lib/pickers/image_picker.dart').
Try correcting the name to the name of an existing method, or defining a method named 'getImage'.
final pickedFile = await picker.getImage(source: ImageSource.camera);
^^^^^^^^
What I have done so far:
Added the dependency to my pubspec.yaml: file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
cloud_firestore: 0.13.5
firebase_auth: 0.16.1
image_picker: ^0.6.7+17
Added android:requestLegacyExternalStorage="true" to the AndroidManifest.xml file
Also Imported import 'package:image_picker/image_picker.dart' to use this library
What could be the problem?
You are trying to use an old API with a plugin version that specifies to use the new API.
Old API
File image = await ImagePicker.pickImage(...)
New API
final _picker = ImagePicker();
.
.
.
PickedFile image = await _picker.getImage(...)
Are you sure the ImagePicker you are using is not the one from this package:chat_app/pickers/image_picker.dart ? Maybe there is a class name conflict and you must rename your own ImagePicker class
I got the same problem I solved by defining the picker like that
final picker = ImagePicker();
and then use this
Future<void> _chooseImage() async {
var pickedFile = await picker.getImage(source: ImageSource.gallery);
}
1)you may forget import the library of "image picker":import 'package:image_picker/image_picker.dart';
2)or import wrong library with the same name with some differences in the syntax of Sentence
Just upgrade to latest version of image_picker.
And replace getImage by pickImage bcz getImage has deprecated.

Flutter in_app_purchase '_enablePendingPurchases': enablePendingPurchases() must be called before calling startConnection

I am using the simple code below
bool available = await InAppPurchaseConnection.instance.isAvailable();
however it is returning the error
E/flutter (14525): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:in_app_purchase/src/billing_client_wrappers/billing_client_wrapper.dart': Failed assertion: line 101 pos 12: '_enablePendingPurchases': enablePendingPurchases() must be called before calling startConnection
I was wondering if anyone knew a reason for this error and if so what should i fo about it, Happy to have any suggestions - thanks.
The documentation is very thin on this and should actually be more clear. You need include the line below in main() for it to work.
void main() {
///Include this in main() so purchases are enabled
InAppPurchaseConnection.enablePendingPurchases();
runApp(MyApp());
}
I could not import InAppPurchaseConnection to try the accepted solution, and fixed this issue with the following:
import 'package:flutter/foundation.dart';
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Inform the plugin that this app supports pending purchases on Android.
// An error will occur on Android if you access the plugin `instance`
// without this call.
if (defaultTargetPlatform == TargetPlatform.android) {
InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
}
runApp(MyApp());
}