-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
[v3] migrating to null safety #334
Conversation
Hi there is something wrong on this branch- when a key isn't found, the app hits an exception. In the old lib, if a key wasn't found, it failed silently so it didn't interrupt the app in any unexpected manner.
Seems like Ahh, so if the string contains a period it's now confused because it thinks it's a nested string key! ie: Can we optionally disable nested checks completely? I don't want to use a |
hi @acoutts plz more detailed example for this bug |
Add this in your json file: {
"Please tap the button..": "Please tap the button.."
} Then in your app, Text('Please tap the button..'.tr()) The key is the lang key should contain a period. |
@acoutts I write test case for this test('instance.tr() ', () {
expect(Localization.instance.tr('Please tap the button..'), 'Please tap the button..');
});
test('tr()', () {
expect(tr('Please tap the button..'), 'Please tap the button..');
});
test('ext tr()', () {
expect('Please tap the button..'.tr(), 'Please tap the button..');
});
test passed |
Hm how strange! So how does the nested key logic distinguish between if you are doing |
@acoutts this is some nested test case
easy_localization/test/utils/test_asset_loaders.dart Lines 48 to 57 in bc8f6da
easy_localization/test/easy_localization_test.dart Lines 136 to 147 in bc8f6da
easy_localization/test/easy_localization_test.dart Lines 219 to 225 in bc8f6da
|
Ah very cool- thanks for showing! Can you see if having 3 periods breaks it? That's the only difference I found from my app vs the test there. |
Thanks! That looks related to my issue. One other thing, I tried to disable the log messages for tests:
But this one still prints every time a test starts:
Is there a way to hide that one? |
Ok I found how to reproduce the issue. The issue is if you try to reference a key that doesn't exist, and that key has a period in it. test('won\'t fail for missing key with consecutive dots', () {
expect(
Localization.instance.tr('Processing.'),
'Processing.',
);
});
Problem is the logic here: bool isNestedKey(String key) =>
!_translations!.containsKey(key) && key.contains('.'); |
Yeah this is tough. I don't think you can figure out if the user is using
|
…references null exception during unit tests
I was able to fix the logic so it won't fail on missing keys with periods, and all of the tests are passing including the shared preferences null error. I had to put I created this PR to put the changes into your branch: #341 All tests are now passing. |
@acoutts nice work 👍 |
Thanks! Love this package, glad I could help.
This is the only head scratcher. I almost think the user needs to give a hint here what kind of key they are using. |
thnx @acoutts , welcome anytime |
Fix crash when a key containing periods doesn't exist. Fixed shared preferences null exception during unit tests
No description provided.