void main() async {
EndPoints.configure();
print(AnsiStyles.red('This is red!'));
print('......env.......${EndPoints.env}........${EndPoints.baseUrl}');
var appToken = "";
if (Platform.isIOS) {
appToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-NRMA';
} else if (Platform.isAndroid) {
appToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-NRMA';
}
Config config = Config(
accessToken: appToken,
analyticsEventEnabled: true,
webViewInstrumentation: true,
networkErrorRequestEnabled: true,
networkRequestEnabled: true,
crashReportingEnabled: true,
interactionTracingEnabled: true,
httpResponseBodyCaptureEnabled: true,
loggingEnabled: true,
printStatementAsEventsEnabled: true,
httpInstrumentationEnabled: true);
BindingBase.debugZoneErrorsAreFatal = false;
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: Colors.white,
statusBarColor: Colors.white.withOpacity(0.5),
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.dark,
));
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await ChargeStationsDatabaseHelper.initDatabase();
FirebaseOptions androidOptions = FirebaseOptions(
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
appId: "1:XXXXXXXXXXXX:android:XXXXXXXXXXXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXX",
projectId: "XXXXXXXXXXXX");
FirebaseOptions iosOptions = FirebaseOptions(
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
appId: "1:XXXXXXXXXXXX:ios:XXXXXXXXXXXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXX",
projectId: "XXXXXXXXXXXX");
await Firebase.initializeApp(
options: Platform.isAndroid ? androidOptions : iosOptions,
);
await FirebaseApi().initPushNotifications();
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance);
FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true);
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
NewrelicMobile.instance.start(config, () {
runZonedGuarded(() async {
// Push notification code commented out
/*
await PushNotificationService
.requestPushNotificationPermission()
.then((value) async {
await PushNotificationService
.registerDevice();
});
await FirebaseApi()
.initNotifications();
*/
// Sentry code commented out
runApp(initalApp());
}, (error, stackTrace) {
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
});
}
The Flutter bindings were initialized in a different zone than is now being used. This will likely cause confusion and bugs as any zone-specific configuration will inconsistently use the configuration of the original binding initialization zone or this zone based on hard-to-predict factors such as which zone was active when a particular callback was set. It is important to use the same zone when calling
ensureInitialized
on the binding as when callingrunApp
later. To make this warning fatal, set BindingBase.debugZoneErrorsAreFatal to true before the bindings are initialized (i.e. as the first statement invoid main() { }
).When the exception was thrown, this was the stack: #0 BindingBase.debugCheckZone. (package:flutter/src/foundation/binding.dart:495:29) binding.dart:495 #1 BindingBase.debugCheckZone (package:flutter/src/foundation/binding.dart:500:6) binding.dart:500 #2 runApp (package:flutter/src/widgets/binding.dart:1212:18) binding.dart:1212 #3 main.. (package:ev/main.dart:189:7) main.dart:189 #8 main. (package:ev/main.dart:160:5) main.dart:160 #9 NewrelicMobile.start. (package:newrelic_mobile/newrelic_mobile.dart:42:13) newrelic_mobile.dart:42 (elided 4 frames from dart:async)
NewrelicMobile.instance.log(
LogLevel.ERROR,
eventName,
);
await NewrelicMobile.instance.recordCustomEvent(
"analytics",
eventName: eventName,
eventAttributes: params,
);
Also this function is not logging anything in my newrelic dashboard.
NewrelicMobile.instance.start()
creates under the hood a new zone. You create another one by calling runZonedGuarded()
. This is the issue.
You can solve it by configuring manually the initialization of New Relic:
void main() async {
runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
//
EndPoints.configure();
print(AnsiStyles.red('This is red!'));
print('......env.......${EndPoints.env}........${EndPoints.baseUrl}');
var appToken = "";
if (Platform.isIOS) {
appToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-NRMA';
} else if (Platform.isAndroid) {
appToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-NRMA';
}
Config config = Config(
accessToken: appToken,
analyticsEventEnabled: true,
webViewInstrumentation: true,
networkErrorRequestEnabled: true,
networkRequestEnabled: true,
crashReportingEnabled: true,
interactionTracingEnabled: true,
httpResponseBodyCaptureEnabled: true,
loggingEnabled: true,
printStatementAsEventsEnabled: true,
httpInstrumentationEnabled: true);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: Colors.white,
statusBarColor: Colors.white.withOpacity(0.5),
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.dark,
));
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await ChargeStationsDatabaseHelper.initDatabase();
FirebaseOptions androidOptions = FirebaseOptions(
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
appId: "1:XXXXXXXXXXXX:android:XXXXXXXXXXXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXX",
projectId: "XXXXXXXXXXXX");
FirebaseOptions iosOptions = FirebaseOptions(
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
appId: "1:XXXXXXXXXXXX:ios:XXXXXXXXXXXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXX",
projectId: "XXXXXXXXXXXX");
await Firebase.initializeApp(
options: Platform.isAndroid ? androidOptions : iosOptions,
);
await FirebaseApi().initPushNotifications();
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance);
FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true);
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
//
FlutterError.onError = (FlutterErrorDetails errorDetails) {
FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
NewrelicMobile.onError(errorDetails);
};
await NewrelicMobile.instance.startAgent(config);
// Push notification code commented out
/*
await PushNotificationService
.requestPushNotificationPermission()
.then((value) async {
await PushNotificationService
.registerDevice();
});
await FirebaseApi()
.initNotifications();
*/
// Sentry code commented out
runApp(initalApp());
}, (Object error, StackTrace stackTrace) {
NewrelicMobile.instance.recordError(error, stackTrace);
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
}
Have a look at NewrelicMobile.instance.start() method(which you called before) one more time, and compare it with the manual initialization(above), notice the difference, make changes if you need to.
Hope it helps.