1 / 1
Sep 2024

PLz Note i all internet & network permssions added befor & my app use to work will but two days ado i got this errors & i am useing my device to debug & test

Exception has occurred.
ArgumentError (Invalid argument(s): argument value for ‘return_value’ is null) << from realm_binding.dart

Exception has occurred.
SocketException (SocketException: Failed host lookup: ‘services.cloud.mongodb.com’ (OS Error: No address associated with hostname, errno = 7))

class ItemService with ChangeNotifier { R.User? user; late R.Realm realm; R.App app; List<Account> accounts = []; List<IsUserPaid> selectedUsers = []; List<int> isPaid = []; List<Account> searchResults = []; Account? currentAccount; bool _itemIsLoading = false; // Loading state bool? get itemIsLoading => _itemIsLoading; ItemService(this.app) { _initialize(); } Future<void> _initialize() async { if (app.currentUser == null) { throw Exception("User is not authenticated"); } user = app.currentUser; await _openRealm(); } Future<void> _openRealm() async { //_setLoading(true); var realmConfig = R.Configuration.flexibleSync( user!, [Mytable.schema, IsUserPaid.schema, Account.schema]); realm = R.Realm(realmConfig); listenToConnectionState(); } Future<void> updateSubscriptions() async { realm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions.clear(); mutableSubscriptions.add(realm.all<Mytable>()); // mutableSubscriptions.add(realm.all<IsUserPaid>()); mutableSubscriptions.add(realm.all<Account>()); }); } Future<void> refreshData() async { try { await realm.subscriptions.waitForSynchronization().then((_) { currentAccount = getCurrentUser(); print(currentAccount?.userName ?? "No User"); refreshToken(); }).catchError((error) { print('Error during subscription synchronization: $error'); }); } catch (e) { print('Exception in refreshData: $e'); } } void listenToConnectionState() { realm.syncSession.connectionStateChanges .listen((R.ConnectionStateChange connectionState) { switch (connectionState.current) { case R.ConnectionState.connected: print("Connected to the Realm server."); updateSubscriptions(); refreshData(); _setLoading(false); break; case R.ConnectionState.connecting: print("Connecting to the Realm server..."); _setLoading(true); break; case R.ConnectionState.disconnected: print("Disconnected from the Realm server."); _setLoading(false); break; } }); } void _setLoading(bool value) { _itemIsLoading = value; notifyListeners(); } Future<void> close() async { if (user != null) { await user?.logOut(); user = null; } realm.close(); } @override void dispose() { realm.close(); super.dispose(); }

if i signout i got
Exception has occurred.
RealmException (RealmException: Accessing object of type Users which has been invalidated or deleted. Error code: 2010.)

Exception has occurred.
RealmException (RealmException: Error getting property Account.email Error: RealmException: Accessing object of type Users which has been invalidated or deleted. Error code: 2010.)

Exception has occurred.
TimeoutException (TimeoutException after 0:01:00.000000: Future not completed)

enum AuthMode { signUp, login } class UserService with ChangeNotifier { AuthMode authMode = AuthMode.login; bool eye = true; bool eye1 = true; TextEditingController emailController = TextEditingController(); TextEditingController nameController = TextEditingController(); TextEditingController confirmPasswordController = TextEditingController(); TextEditingController passController = TextEditingController(); GlobalKey<FormState> formKey = GlobalKey<FormState>(); AutovalidateMode autovalidateMode = AutovalidateMode.disabled; String id; App atlasApp; User? currentUser; late Account currentAccount; bool _userIsLoading = false; // Loading state bool? get userIsLoading => _userIsLoading; // bool? get userIsLoading => _userIsLoading; UserService(this.id) : atlasApp = App(AppConfiguration(id)); Future<User> registerUserEmailPassword( String email, String password, String name, String token) async { EmailPasswordAuthProvider authProvider = EmailPasswordAuthProvider(atlasApp); _setLoading(true); // Start loading try { await authProvider.registerUser(email, password); User loggedInUser = await atlasApp.logIn(Credentials.emailPassword(email, password)); await setRole(loggedInUser, email, name, token); currentUser = loggedInUser; _setLoading(false); // Stop loading notifyListeners(); return loggedInUser; } catch (e) { _setLoading(false); // Stop loading if an error occurs rethrow; // Re-throw the exception after stopping the loading indicator } } void _setLoading(bool value) { _userIsLoading = value; notifyListeners(); } Future<User> logInUserEmailPassword(String email, String password) async { _setLoading(true); // Start loading Credentials credentials = Credentials.emailPassword(email, password); final loggedInUser = await atlasApp.logIn(credentials); currentUser = loggedInUser; _setLoading(false); // Start loading notifyListeners(); return loggedInUser; } Future<void> setRole( User loggedInUser, String email, String name, String token) async { final realm = Realm(Configuration.flexibleSync(loggedInUser, [Account.schema])); String subscriptionName = "rolesSubscription"; realm.subscriptions.update((mutableSubscriptions) => mutableSubscriptions.add(realm.all<Account>(), name: subscriptionName)); await realm.subscriptions.waitForSynchronization(); realm.write(() { currentAccount = Account(ObjectId(), email, name, loggedInUser.id, token); return realm.add(currentAccount); }); realm.subscriptions.update((mutableSubscriptions) => mutableSubscriptions.removeByName(subscriptionName)); await realm.subscriptions.waitForSynchronization(); realm.close(); } Future<void> logoutUser() async { await currentUser?.logOut(); currentUser = null; }
runApp( MultiProvider( providers: [ ChangeNotifierProvider<DataTableProvider>( create: (_) => DataTableProvider(), ), ChangeNotifierProvider<LanguageProvider>( create: (_) => LanguageProvider(), ), ChangeNotifierProvider<ConnectivityProvider>( create: (_) => ConnectivityProvider(), ), ChangeNotifierProvider<PdfProvider>( create: (_) => PdfProvider(), ), ChangeNotifierProvider<UserService>(create: (_) => UserService(appId)), ChangeNotifierProxyProvider<UserService, ItemService?>( // RealmServices can only be initialized only if the user is logged in. create: (context) => null, update: (BuildContext context, UserService appServices, ItemService? realmServices) { return appServices.atlasApp.currentUser != null ? ItemService(appServices.atlasApp) : null; }), ], child: const Jamia(), ), ); } class Jamia extends StatelessWidget { const Jamia({super.key}); @override Widget build(BuildContext context) { final provider = Provider.of<DataTableProvider>(context, listen: true); final itemService = Provider.of<ItemService?>(context); final con = Provider.of<ConnectivityProvider>(context, listen: true); SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle( systemNavigationBarIconBrightness: provider.tm == ThemeMode.light ? Brightness.dark : Brightness.light, statusBarIconBrightness: provider.tm == ThemeMode.light ? Brightness.dark : Brightness.light, systemNavigationBarColor: provider.tm == ThemeMode.light ? const Color(0xffFEFBF7) : Color(0xFF1F1F1F), statusBarColor: provider.tm == ThemeMode.light ? const Color(0xffFEFBF7) : Color(0xFF1F1F1F), statusBarBrightness: provider.tm == ThemeMode.light ? Brightness.light : Brightness.dark, ), ); WidgetsBinding.instance.addPostFrameCallback((_) { if (con.isConnected && itemService?.itemIsLoading == true) { itemService?.refreshData(); } }); return MaterialApp( locale: Locale(provider.local), localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: S.delegate.supportedLocales, navigatorKey: navigatorKey, title: "Jamia", debugShowCheckedModeBanner: false, themeMode: provider.tm, theme: lightTheme(context), // Use the light theme darkTheme: darkTheme(context), // Use the dark theme routes: { SplashView.routeName: (context) => const SplashView(), GeneratedTableScreen.routeName: (context) => const GeneratedTableScreen(), DragDropListView.routeName: (context) => const DragDropListView(), Setting.routeName: (context) => const Setting(), TablesScreen.routeName: (context) => const TablesScreen(), LoginSignup.routeName: (context) => const LoginSignup(), FriendsAddedMeScreen.routeName: (context) => const FriendsAddedMeScreen(), }, home: itemService?.isLogedIn() ?? false ? con.isConnected ? itemService?.itemIsLoading == true ? WaitingIndicator(con: con) : const TablesScreen() : const TablesScreen() // Show TablesScreen when loading is complete : const LoginSignup(), ); } }