Is it possible to store a variable or function value in the list of flutter(dart)? - flutter

One person in Stackover Flow gave me a hint about creating a learning page.
Using the list, save the necessary data, id and favorite variables, and call them to the index number.
I was creating a class to implement it.
However, I realized that variables could not be stored in the list...
Is there a way to save it?
And I don't make a separate class, but I'm going to make a list in the file with the following code.
But before, I heard that using global variables makes me stutter and it's bad for memory.
Shall we use "const"?
If not, wouldn't it be a problem how to make the class?
Of course, favorite variables cannot be used because they change from time to time.
const List<Function> fav_1 = [favoriteButton_0_01_01,.....];
Is it okay to use only the const list as a global variable instead of making a class?
Can I put variables in the list? Then, how?

You can only put items with a matching type in the list.
if you define a list like "List" than only functions can be saved there.
if you define a list like "List" than only Integers can be saved there.
using const as a modifier will result in an unmodifiable list and so you won't be able to put anything in there.

Related

Is specifying list items type important in Dart?

I recently started learning Flutter and hence Dart.
Unlike Python, everyone seems to be specifying the datatype of the list items whenever they create a list in Dart. I don't really want to, so is it really important to do so, or is it just one of those norms?
List<String> names = [
"Faisal",
"Saifi"
];
It still works without doing it so let me know should I or should I not. As there isn't really this question anywhere asked here (Or I didn't come across it).
You don't need to specify the type of list when you are defining it, but in a complex app in order to avoid facing assigning value error, it is good to define list with type.
for example you supposed to getting List of string from api bit some you are getting list of int if you define you list like List, you never notice that and you will get error some where else in you complex app, but if you define your list like List<String> you will get exception on that and you now why that is happening.

Collect internal variables of nested functions in matlab

I have a project consisting of multiple nested functions.
For debugging purpose I want to save all internal variables in one way or another, in order to display figures, replay parts of code etc...
I also want to keep this as transparent as possible regarding calculation time.
My first thought was to create a global variable, and store programmatically at the end of each function the inputs and outputs inside the variable as a structure :
globalVariable.nameOfParentfunction_NameOfFunction.nameInput1 = valueInput1;
globalVariable.nameOfParentfunction_NameOfFunction.nameInput2 = valueInput2;
...
globalVariable.nameOfParentfunction_NameOfFunction.nameOutput1 = valueOutput1;
...
Is it possible to use some kind of reflection to get the name and value of inputs/outputs without necessarily parse the file where the function is written?
I found a good but maybe outdated topic about parsing
How do I collect internal signals?
The simple solution is to use save, which will save all variables in the current workspace (the function’s context) to file.
If you want to keep the values in memory, not in a file, you can use names = who to get a list of all variables defined in the current workspace, then use val = eval(names{i}) to get the value of the variable called name{i}.
I would recommend putting all of that in a separate function, which you can call from any other function to store its variables, to avoid repeating code. This function would use evalin('caller',…) to get names and values of variables in the workspace of the calling function.
Note that using eval or evalin prevents MATLAB from optimizing code using its JIT. They also are dangerous to use, since they can execute arbitrary code, however in this case you control what is being executed so that is no a concern.

Passing An Object Instance By Value In Dart

I have an object that was created with GetxController and it has a list field. I want to select a specific item in that list and change some parameters. But I should be able to cancel this changing scenario. Because when I select an item and change it, also change that class list item.
In Dart, objects pass by reference. But I need to pass it by value for canceling change. There's any way to pass an object instance by value?
In this kind of scenario, you should try to use immutable types.
There are good Dart libraries for that, even if the language doesn't have native support for it... with truly immutable data types, you essentially get pass-by-value semantics. They also make it easy to make copies of your data with small modifications on the returned value (while the original obviously remains unmodified).
Example packages you could use:
built_collection
built_value
freezed
No.
But you can just make a copy yourself and pass that. And depending on whether the change was confirmed you can eiter copy it back into your list or not.

Is it possible to get the type of a variable while computing completion suggestions?

I'm thinking of creating a VSCode extension to help people use a library I am creating. I've looked in 50 places and can only see documentation on getting the plain text of the document in which the completion suggestions are triggered.
My library exposes a function with two parameters, both objects with the same keys, but the first one will be defined already and the 2nd one will be passed in as an object literal. For example
const obj1 = {a:1, b:2};
doLibraryThing(obj1, {a:[], b:[]});
I want to provide code completion, or a snippet, or anything that can detect that doLibraryThing is being called, and know what properties were defined in obj1, even though usually it will be imported from another file; and then use those properties to generate the suggestion with the same properties, {a:[], b:[]}.
Is this possible?

When does Inspector in unity assign variable?

Say i have a public list of integers then of course I will see the list in unity inspector and i can assign multiple values inside it. My question is when the list will actually assign the values to the variables in the game?? Does it assign values in "OnEnable()", "OnAwake()", "OnStart()".
During deserialization
Which occurs before any method of that script's code is called.
If you want to run code at that point in time, you need an ISerializationCallbackReceiver. Note that the intended use of this interface is to serialize/deserialize certain complex Types (such as dictionaries) for use in the Inspector; I have not attempted to use this in a runtime capacity even though the interface does appear to be in UnityEngine not UnityEditor.