Reputation: 2175
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.
Upvotes: 1
Views: 66