Kotlin changes parameter names to alphabetical values on release for a Flutter app - flutter

I recently started running into an issue, where, when building my Flutter in release mode to deploy to Play Console's internal testing track, some of my functions in Flutter started failing.
For context, I have EventChannels that stream data from a native function to Flutter, from which I construct a Flutter object.
After countless hours of investigation, it turned out that, in debug mode, the JSON string I'm constructing in Kotlin, contains the correct keys, however, when doing the same thing in release, the keys turn to a:, b:, c:, etc.
At this point in time, I've got no obfuscation enabled in the app, and I'm not too sure why this would have suddenly broke.
I can't cater for the actual names, and alphabetical values in my toJson() function on my class, so want to know how, in release, can I get my parameter values back?
The kotlin class that's encoded to JSON looks like this:
class ScanResponseModel(var name: String, var mac: String, var axis: String, var number : String)
The json output for this, in DEBUG, looks like this:
[{
"name":"2325",
"mac":"D4:1C:32:33:EE:1F",
"axis":"left",
"number":"0002325"
}, {
"name":"2122",
"mac":"DC:20:3F:E7:05:B7",
"axis":"right",
"number":"0002122"
}]
The exact same output in RELEASE, looks like this:
[{
"a":"2325",
"b":"D4:1C:32:33:EE:1F",
"c":"left",
"d":"0002325"
},
{
"a":"2122",
"b":"DC:20:3F:E7:05:B7",
"c":"right",
"d":"0002122"
}]

Related

Firebase Error in Retrieving - Syntax Error

Stumbled on something odd and was wondering for some input. I have a dynamic child naming system and want to retrieve data. Now, when I try to input the dynamic naming of child it does not retrieve it however when I do it manually it does. I have debugged via print, and it seems to be working as well as other forms of observation. Any clue?
Assuming test = code test (to make it easier). Could it be the way the statements are wrote? The working one uses queryOrdered where as the other uses observe?
Working Type:
let refPosts = Database.database().reference().child("postsof"+"\(test)").queryOrdered(byChild: "username").queryEqual(toValue: "\(result)")
Does Not Work:
Database.database().reference().child("postsof"+"\(test)").observe(DataEventType.value)
Works Manually:
Database.database().reference().child("postsoftest").observe(DataEventType.value)
Edit:
Print: For all print statements, it shows as "postsoftest". This confirms that for the second example, "postsof"+" \ (test)" is being read correctly on the debugger as postsoftest, however does not retrieve the data as the other 2 examples.
JSON:
"postsoftest": {
"autoID": {
"name": "jack"
"link": "..."
}
},

passing dynamic strings to AppLocalizations.of(context)! in Flutter

right now Im working in App using Flutter and I have 4 different languages, I use json (arb files) for localization (translation)
I need to pass different string values which app fetch them using API's as shown in example below
AppLocalizations.of(context)!snapshot.data![index].state_pickup[0]
however "AppLocalizations.of(context)!" doesn't fetch the return data from snapshot.data![index].state_pickup[0] and instead it looks for it as string and tries to search for match string name in AppLocalization.dart class?
Any idea how I can pass dynamic string arguments to AppLocalizations.of(context)!?
What you are trying to do, invoking a method by its name at runtime, is called reflection, and this is not supported by Flutter natively (though there are packages that try to emulate this, but I have no experience with them).
What will work for you, even though it might be tedious, is manually mapping your value from the API to the corresponding method from AppLocalizations.of(context).
String localizedString = getLocalizedString(snapshot.data![index].state_pickup[0], context);
String getLocalizedString(String key, BuildContext context) {
switch (key) {
case "possible_api_value_1":
return AppLocalizations.of(context)!.possibleApiValue1;
case "possible_api_value_2":
return AppLocalizations.of(context)!.possibleApiValue2;
...
}

How can I reduce the copied code using Riverpod

I feel myself copying a lot of the same code using Riverpod. An example, if I have something like this:
...modelList.when(
data: (data) { display page when data returns },
loading: () { display disabled version of page until data returns} ,
error: (error, st) { display page with error message },
)
I find myself displaying the a version of the page in 3 different places. This feels very repetitive and I feel I must be doing something wrong. Suggestions?
How do you propose you could solve this in less code?
You need to handle different states in your app; I'm unsure how you could do that without specifying the desired behavior for each state.
You aren't doing anything wrong. Try using bloc (for example) and you will see that Riverpod is really lightweight for what it provides.

In a list, set the default sort column in jhipster

sorry for simple question, but I'm new both to spring, JPA and Jhipster.
I'm following a video tutorial, and in one step the teacher was "customizing" the default view to sort on a custom column. He did so by changing the method in the repository class, to a query that ordered by one of the columns. This works, but I noticed that doing that the UI sort (the sort the UI impose clicking on the column) stopped working.
Debugging i noticed that the reason is that the query filter first by date, then by "pageable".
What is the best practice to apply the "byDate" sort just as a default, in case the pageable is empty?
I managed to "hack" the system by deep inspecting the page object and with an "if there is an UI sort use repository method A (the one that is natively unsorted), if there is not use repository method B (the one that is already sorted)". What I'm looking for is the "right way", the best practice, because I want to learn to program the way it is supposed to be, and I'm pretty sure that to have a default sort column is not a such exotic request
Here it is the link to the video
many thanks
You can set the default sorting column of any view in the [component-name].route.ts. In that file you will see something like this:
// ...
export const fooRoute: Routes = [
{
path: '',
component: FooComponent,
resolve: {
pagingParams: JhiResolvePagingParams
},
data: {
authorities: ['ROLE_USER'],
defaultSort: 'id,asc', // <- Look at this line :)
pageTitle: 'jhipsterApp.foo.home.title'
},
canActivate: [UserRouteAccessService]
},
// ...
The default order set by JHipster is by column id in ascending order. If you want to set the default order by column name descending (just as an example) just change that line to the following:
defaultSort: 'name,desc',
My app is generated via recent JHipster 7.4.1 and uses Vue frontned.
There are no [component-name].route.ts files generated.
I tried to add defaultSort into entities.ts but no luck.
This is working here:
In the [entity-name].components.ts,
change
public propOrder = 'id';
into
public propOrder = '[your default sort column, e.g. name]';

user_work_history with Flex and the ActionScript SDK

I'm working on a sample app for Facebook, using Flash Builder and Flex.
Now, I've got everything up and running - but there's one problem, specifically with the work history part.
When I try to display the user's work history..here's the code for logging in:
protected function login():void
{
FacebookDesktop.login(loginHandler, ["user_birthday", "user_work_history"]);
}
Here, loginHandler's a callback function, that then goes ahead and displays data about the user:
protected function loginHandler(success:Object,fail:Object):void
{
if (success){
currentState = "LoggedIn";
fname.text = success.user.name;
userImg.source=FacebookDesktop.getImageUrl(success.uid,"small");
birthdayLbl.text=success.user.birthday;
workLbl.text=success.user.work;
}
}
Now, the problem occurs with success.user.work - it ends up printing the following:
[object,Object],[object,Object],[object,Object],[object,Object]
Obviously, I'm doing something wrong..but I can't figure out what exactly it is. Would be grateful for some pointers!
Thanks!
Rudi.
The object contained in success.user.work is most likely an array of objects, each item representing a work period, so you'll have to treat it as such. Either use a list and a custom renderer for each item, or create a string by iterating over the array, and appending the fields that you're interested in.
To see what the individual objects contain, either use a breakpoint during debug and inspect them, or check to see if they're documented in the facebook development documentation.