1

I have a flutter app where I use Firebase Auth and Firebase Database.

The app works fine on my android phone. I am able to authenticate and add data to the database.

The issue is on Iphone. The firebase auth works fine because I am able to authenticate and get the UserCredentials, but pushing to firebase loads indefinitely until timeout.

P.S This only happens on the IOS simulator. On a real iphone device, it works

I have already done all the firebase part because I used flutterfire. So it already generates the files for you. I even added the GoogleService-Info.plist manually in xcode project.

Also, when i created my project, i have enabled auth and database first before generating the files with flutterfire. So i already have the updated google-services files with the database url in it.

Below is my code:

main.dart

void main() async {
  // Ensure the widgets are initialized
  WidgetsFlutterBinding.ensureInitialized();

  // Load firebase
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  // Initialize the shared preferences
  final prefs = await SharedPreferences.getInstance();

  // Intialize the app settings
  final repository = AppSettingsImpl(prefs);

  // Run the main app
  runApp(
    ProviderScope(
      overrides: [
        settingsRepositoryProvider.overrideWithValue(repository),
      ],
      child: const MyApp(),
    ),
  );
}

user_repo.dart

class GUserImpl implements UserRepository {
  final FirebaseDatabase _database = FirebaseDatabase.instance;
  final String _usersPath = 'users';

  GlamUserImpl();

  DatabaseReference get _usersRef => _database.ref(_usersPath);

  @override
  Future<void> createUser(GUser user) async {
    try {
      await _usersRef.child(user.id).set(user.toJson());
    } catch (e) {
      print(e);
      throw ErrorDescription('Failed to create user');
    }
  }
}

provider.dart

print("Pushing to firebase");

      // Push this user to the database
      await GUserImpl()
          .createUser(gUser)
          .timeout(const Duration(minutes: 1));

In my provider.dart, it displays the "pushing to firebase" message and then loads indefinitely.

IS there a way to see what's blocking it ? I don't have much experience with xcode and ios, just flutter and android.

8
  • Can you share the code of the createUser method? Also, do you see a request being triggered to firebase? Commented Feb 14 at 7:48
  • @tomerpacific i have already shared it. it's the user_repo.dart part. How can i check if the request is trigerred in firebase ? Commented Feb 14 at 7:51
  • @tomerpacific So in firebase usage, i can see just one connection (which is my android phone). So no connection for Iphone Commented Feb 14 at 7:54
  • You can use a third party tool (like proxyman or charles proxy). Also, when debugging the code do you see the correct arguments being passed? Commented Feb 14 at 7:54
  • Yes the correct arguments are passed. And also, it works as intended for android. I think the indefinite loading means it can't access the database for some reason on IOS but i don't know why. And i don't see any errors or anything to troubleshoot this further Commented Feb 14 at 7:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.