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());
}
Related
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.
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
I am implementing Crashlytics with flutter,
and following this docs Using Firebase Crashlytics
I was wondering what would actually happen if an error is thrown inside runZonedGuarded's
error callback: (see the arrow in the code)
void main() async {
runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
runApp(MyApp());
}, (error, stackTrace) async {
***** some buggy code here ******. <----------
await crashlytics.handleNonFlutterErrors(error,stackTrace);
});;
}
so I have tried it, and to my surprise it is still swallowed by flutter framework and stacktrace was dumped to console - I was expecting the app to crash but it didn't...
does any-body knows how to handle this types of errors?
E/flutter (26872): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)]
Unhandled Exception: Null check operator used on a null value
E/flutter (26872): #0
MethodChannelFirebaseMessaging.registerBackgroundMessageHandler
(package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:173:53)
E/flutter (26872): #1
FirebaseMessagingPlatform.onBackgroundMessage=
(package:firebase_messaging_platform_interface/src/platform_interface/platform_interface_messaging.dart:108:16)
// Background Messaging Set Up
Future<void> _firebaseMessagingBackgroundHandler(
RemoteMessage message) async {
print('background message');
}
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(....)
I am getting an error for this code on Android system. Everything works except when the app is terminated.
What works on Android:
Notification when Terminated, onBackground and onForeground
Date only when onForeground
What does not work on Android:
Data only when Terminated and onBackground
What works on iOS:
Notification when Terminated, onBackground and onForeground
Date only when onForeground
What does not work on iOS:
Data only when Terminated,
I have no clue why I am getting that null value error on Android system and how can I fix this issue? Also, is it true that I can not receive the Data only push notification on iOS when the app is terminated?
I had the same error as like you, on the same line. I checked out docs and it says 2 things about background message handler.
It must not be an anonymous function.
It must be a top-level function (e.g. not a class method which requires initialization).
In my case it was not a top-level function, it was declared inside a class. When you move your handler out of any class or function, so that it is a top-level function and doesn't require any class or method initialisation then the error will be gone.
_firebaseMessagingBackgroundHandler function should be outside of the main function.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
}
Future<void> main() async {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(
...
);
}
In my case, doing what docs said was not enough. So I realized that I should add WidgetsFlutterBinding.ensureInitialized() before everything in main function like this:
void main() {
WidgetsFlutterBinding.ensureInitialized();
FirebaseMessaging.onBackgroundMessage(_handleMessage);
runApp(const Homino());
}
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());
}