ilteoood / flutter_i18n

I18n made easy, for Flutter!
MIT License
217 stars 57 forks source link

How do I know if a JSON string has loaded? #131

Closed phamquoctrongdev closed 3 years ago

phamquoctrongdev commented 4 years ago

I use NetworkFileTranslationLoader to load json file from my server. But when I switch between languages there is a delay (a few seconds). I want to show CircleLoading while waiting for the json file to download. How do I do this?

ilteoood commented 4 years ago

Hi @pqtrong17 , In this moment the only method that you have is to listen the _localeStream inside FlutterI18n class. How do you change the language?

I would like to add a new stream with the loading status: @defint what do you think?

phamquoctrongdev commented 4 years ago

Sorry, my English is not good. I get a error not found a key for translate because json file is not finish. I need a bool value to listen.

defint commented 4 years ago

@ilteoood Yes, nice to have this feature to prevent a lot of issues.

ilteoood commented 4 years ago

@defint I forgot to create a new branch. Can you give me a feedback about this? https://github.com/ilteoood/flutter_i18n/commit/f00daf72287f91d3de1a565c9ffd69b079225050

defint commented 4 years ago

@ilteoood Looks good, but I have some comments: 1) I would create another getter with a transformed stream (https://api.flutter.dev/flutter/dart-async/Stream/transform.html). Transformed stream should return a boolean value to easy usage. I, as a user, don't want to import enum and listen notLoaded / loading values. 2) Documentation with the example of usage will be helpful

ilteoood commented 4 years ago

@pqtrong17 support has been implemented in this commit: https://github.com/ilteoood/flutter_i18n/pull/136/commits/6c552379b46c156aac3bed33637c4a89a55b075b

It'll be available with version 0.20.0

phamquoctrongdev commented 3 years ago

@ilteoood If I combine with StreamBuilder, When I call setState, I get a error: Bad state: Stream has already been listened to.

ilteoood commented 3 years ago

@pqtrong17 how are you using it? I've made an example of usage here: https://github.com/ilteoood/flutter_i18n/blob/420fb66bac326bb438c5092a4274151a98c20eb0/example/lib/network_example.dart#L64