-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving data to Firestore not working ONLY ON PRODUCTION #112
Comments
Does it work outside an isolate?
… On 24 Jun 2022, at 9:17 PM, Carlos Eduardo Gomes Thiesen ***@***.***> wrote:
Hi,
I'm using the FlutterIsolates to save mass data to my Firestore server. When I test it running from Android Studio, it works perfectly. But, when I send it to Internal Test, the data never reaches the firestore server.
`
void saveStall(String payload) async {
final mainIsolatePort = ReceivePort();
final saveIsolate = await FlutterIsolate.spawn(
saveStallToFirestore, mainIsolatePort.sendPort);
mainIsolatePort.listen(
(messageFromSaveIsolate) {
if (messageFromSaveIsolate is SendPort) {
messageFromSaveIsolate.send(payload);
}
if (messageFromSaveIsolate is String) {
if (messageFromSaveIsolate == 'ok') {
saveIsolate.kill();
mainIsolatePort.close();
} else {
//TODO: treat error
}
}
},
onDone: () {},
onError: (e) {
saveIsolate.kill();
mainIsolatePort.close();
});
}
saveStallToFirestore(SendPort mainIsolatePort) async {
final saveStallToFirebaseIsolatePort = ReceivePort();
try {
mainIsolatePort.send(saveStallToFirebaseIsolatePort.sendPort);
saveStallToFirebaseIsolatePort.listen((messageFromMainIsolate) async {
if (messageFromMainIsolate is String) {
var json = jsonDecode(messageFromMainIsolate, reviver: dateDecoder);
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
StallRepository.instance.update(
farmId: json['farmId'], id: json['id'], json: json['stall']);
List<dynamic> ovines =
json['ovines'].map((e) => Ovine.fromJson(e['id'], e)).toList();
for (Ovine o in ovines) {
OvineRepository.instance
.update(farmId: json['farmId'], id: o.id, json: o.toJson());
}
mainIsolatePort.send('ok');
}
});
} catch (err) {
mainIsolatePort.send('error');
}
}
//Method called by OvineRepository.instance.update in the above snippet
Future? update(
{required String farmId,
required String id,
required Map<String, dynamic> json,
SendPort? messenger}) {
try {
var result = FirebaseFirestore.instance
.collection(farmsCollectionKey)
.doc(farmId)
.collection(ovinesCollectionKey)
.doc(id)
.update(json);
if (messenger != null) {
messenger.send('ok');
}
return result;
} catch (e) {
Get.snackbar(
'error'.tr,
e.toString(),
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.white,
colorText: Colors.black,
);
return null;
}
}
`
Any ideas what I may be doing wrong? Thanks in advance.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
@nmfisher yes, they work outside the isolate in production. Inside only when debbuging |
Here's my flutter doctor (obs: I also tested in stable branch, same issue)
And pub spec
|
Have you tried calling |
@nmfisher thanks for the suggestion. I tried now and received the following error: |
Do you have authentication set up on your Firebase database, and if so, how/where in the app are you authenticating?
… On 25 Jun 2022, at 4:16 AM, Carlos Eduardo Gomes Thiesen ***@***.***> wrote:
@nmfisher thanks for the suggestion. I tried now and received the following error:
Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
Yes, I have authentication set up. |
Sorry I did reply to this via e-mail but it looks like GitHub didn't put it through. Can you try manually authenticating to Firebase inside the same isolate before saving the data? |
Hi @nmfisher. That happened to me too ;D I'll test that as soon as I can. But I don't see this working in a real scenario, since I have authentication via phone number, email and social networks. |
Was this resolved? |
Hey @nmfisher . I didn't have a change to test your latest suggestion. But, as I mentioned, it would not be a viable solution in my case. My solution was to remodel my database to have smaller objects. Thanks for the attention and help. |
That was not a solution, it was a debugging step to check whether authenticating to a Firebase instance outside an isolate also authenticates to the instance inside the isolate (I suspect it doesn't). I will leave this open so if anyone has a similar problem in future, please try this first and report here. |
Try this PR, it might fix it. #118 |
I have the same problem. The app is working in debug model but not in release mode. Could you please publish a new version with the proposed fix? |
Yes, I have authentication set up.
When the user opens the app a listener checks the firebase credentials and
if they are not valid, routes the user to the auth screen.
Em sáb., 25 de jun. de 2022 00:31, Nick Fisher ***@***.***>
escreveu:
… Do you have authentication set up on your Firebase database, and if so,
how/where in the app are you authenticating?
> On 25 Jun 2022, at 4:16 AM, Carlos Eduardo Gomes Thiesen ***@***.***>
wrote:
>
> @nmfisher thanks for the suggestion. I tried now and received the
following error:
> Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been
created - call Firebase.initializeApp()
>
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> You are receiving this because you were mentioned.
—
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABR3LYEDLHM6HD5GHT4HUN3VQZ4RPANCNFSM5ZX2L5AA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Can you try manually authenticating to Firebase inside the same isolate before saving the data?
… On 26 Jun 2022, at 5:32 AM, Carlos Eduardo Gomes Thiesen ***@***.***> wrote:
Yes, I have authentication set up.
When the user opens the app a listener checks the firebase credentials and if they are not valid, routes the user to the auth screen.
It does not happen inside an isolate though
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
@eduardothiesen we've recently published fixes for issues running Flutter > 3.3 in release mode, can you advise if these have fixed your issue? |
Hi,
I'm using the FlutterIsolates to save mass data to my Firestore server. When I test it running from Android Studio, it works perfectly. But, when I send it to Internal Test, the data never reaches the firestore server.
Any ideas what I may be doing wrong? Thanks in advance.
The text was updated successfully, but these errors were encountered: