I want to implement, that when the User has no Internet Connection(Not Connected to Wlan, Ethernet or Cellular) to display a separate Page. For that I use the connectivity_plus Plugin in Version 2.0.1, Flutter 2.5.2 and NO Null-Sound-Safety.
Switching the Smartphone to Airplane mode from Wlan or Cellular Connection the InternetConnection Page is displayed but disabling Airplanemode and having Cellular or Wlan I get The following _CastError was thrown building Builder(dirty): Null check operator used on a null value.
I tried to use Conditional Operators that didn't helped added the home function to the else Statement and added also there the Conditional Operator for the home and for the initialRoute that also didn't helped and now I'm clueless and what I can do.
import 'dart:async';
import 'dart:io';
import 'package:app/env.dart';
import 'package:app/generated/l10n.dart';
import 'package:app/provider/app_clock.dart';
import 'package:app/provider/auth.dart';
import 'package:app/provider/internet_connection.dart';
import 'package:app/provider/local_auth.dart';
import 'package:app/provider/therapist.dart';
import 'package:app/provider/therapy.dart';
import 'package:app/provider/user.dart';
import 'package:app/routes.dart';
import 'package:app/services.dart';
import 'package:app/theme.dart';
import 'package:app/ui/screens/setup/internet_connection.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'package:localizely_sdk/localizely_sdk.dart';
import 'package:provider/provider.dart';
import 'util/http_overrides.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
if (defaultTargetPlatform == TargetPlatform.android) {
// For the GooglePlay billing library 2.0 on Android, it is mandatory to call
// [enablePendingPurchases](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder.html#enablependingpurchases)
// as part of initializing the app.
InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
}
if (AppEnv.LOCALIZELY_SDK_TOKEN.isNotEmpty) {
Localizely.init(
AppEnv.LOCALIZELY_SDK_TOKEN,
AppEnv.LOCALIZELY_DISTRUBUTION_ID,
); // Init sdk
Localizely.setPreRelease(true);
await S.load(S.delegate.supportedLocales.first);
try {
dynamic result = await Localizely.updateTranslations();
AppEnv.localizelySDKenabled = true;
AppEnv.currentLocalizelyReleaseId = result.newReleaseId;
} catch (e) {
AppEnv.localizelySDKenabled = false;
}
} else {
await S.load(S.delegate.supportedLocales.first);
}
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
HttpOverrides.global = MyHttpOverrides();
bool isFirebaseInit = false;
String errorMessage = '';
try {
await Firebase.initializeApp();
// All Services and Providers are being initialized
setupServices(); //needs Firebase
// And we are waiting until that's done
print("Wating for services");
await services.allReady(timeout: Duration(seconds: 60));
print("Services initialized");
// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
if (kDebugMode) {
// Crashlytics does not support web for now. See two other kIsWeb too.
if (!kIsWeb) {
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(false);
}
}
if (!kIsWeb) {
// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
}
isFirebaseInit = true;
} on Exception catch (exception, stack) {
errorMessage += "'${exception.toString()}'\n\nStack:\n${stack.toString()}";
} catch (error, stack) {
errorMessage += "'${error.toString()}'\n\nStack:\n${stack.toString()}";
}
if (!isFirebaseInit) {
runApp(
Container(
color: const Color(0xff008587),
child: Center(
child: Text('''Es tut uns Leid!
Es ist ein Fehler aufgetreten. Wenden Sie sich bitte an .
$errorMessage''', textScaleFactor: 0.8, textDirection: TextDirection.ltr),
),
),
);
} else {
runZonedGuarded(() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: services.get<ConnectivityService>(),
),
ChangeNotifierProvider.value(
value: services.get<AppClock>(),
),
ChangeNotifierProvider.value(
value: services.get<UserProvider>(),
),
ChangeNotifierProvider.value(
value: services.get<TherapyProvider>(),
),
ChangeNotifierProvider.value(
value: services.get<AuthProvider>(),
),
ChangeNotifierProvider.value(
value: services.get<TherapistProvider>(),
),
ChangeNotifierProvider.value(
value: services.get<LocalAuthProvider>(),
),
],
child: MyApp(),
),
);
}, (Object error, StackTrace stackTrace) {
if (!kIsWeb) {
FirebaseCrashlytics.instance.recordError(error, stackTrace);
}
});
}
}
class MyApp extends StatelessWidget {
MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Consumer3<UserProvider, AppClock, ConnectivityService>(
builder: (context, userProvider, clock, connectivityService, _) {
if (connectivityService.connectivityResult == ConnectivityResult.none) {
return MaterialApp(
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
home: InternetConnection(),
);
} else {
return MaterialApp(
title: '',
theme: AppTheme.base,
routes: Routes.routes,
initialRoute: services.get<UserProvider>().guessInitialRoute(),
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
);
}
},
);
}
}
System info
Issue occurs on: both
Plugin name: connectivity_plus
Plugin version: 2.0.1
Flutter doctor output:
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.6 20G165 darwin-x64, locale de-DE)
• Flutter version 2.5.2 at /Users/blackbox/Developing/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 3595343e20 (6 days ago), 2021-09-30 12:58:18 -0700
• Engine revision 6ac856380f
• Dart version 2.14.3
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at /Users/blackbox/Library/Android/sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.0, Build version 13A233
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
I want to implement, that when the User has no Internet Connection(Not Connected to Wlan, Ethernet or Cellular) to display a separate Page. For that I use the connectivity_plus Plugin in Version 2.0.1, Flutter 2.5.2 and NO Null-Sound-Safety.
Switching the Smartphone to Airplane mode from Wlan or Cellular Connection the InternetConnection Page is displayed but disabling Airplanemode and having Cellular or Wlan I get The following _CastError was thrown building Builder(dirty): Null check operator used on a null value.
I tried to use Conditional Operators that didn't helped added the home function to the else Statement and added also there the Conditional Operator for the home and for the initialRoute that also didn't helped and now I'm clueless and what I can do.
System info
Issue occurs on: both Plugin name: connectivity_plus Plugin version: 2.0.1 Flutter doctor output:
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.6 20G165 darwin-x64, locale de-DE) • Flutter version 2.5.2 at /Users/blackbox/Developing/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 3595343e20 (6 days ago), 2021-09-30 12:58:18 -0700 • Engine revision 6ac856380f • Dart version 2.14.3
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /Users/blackbox/Library/Android/sdk • Platform android-30, build-tools 30.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 13.0, Build version 13A233 • CocoaPods version 1.11.2
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.60.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.27.0
[✓] Connected device (3 available) • SM G955F (mobile) • ce0717174bdce4140c • android-arm64 • Android 9 (API 28) • H4x0r12 (mobile) • 00008101-000961681110001E • ios • iOS 15.0.1 19A348 • Chrome (web) • chrome • web-javascript • Google Chrome 94.0.4606.71 ! Error: H4x0r12 is busy: Making the device ready for development. Xcode will continue when H4x0r12 is finished. (code -10)
• No issues found!