After assigning a value in my settler, checking with debugger I am getting null? - flutter

I have this dart/flutter provider
class Cars with ChangeNotifier {
List<Car> _items = [];
Car _selectedCar;
final Auth auth;
Cars(this.auth, this._items);
List<Car> get items {
return [..._items];
}
Car get getCar {
return _selectedCar;
}
void setSelectedCar(Car car) {
_items.add(car);
_selectedCar = car; // here I am getting null from _selectedCar
notifyListeners();
}
}
Checking with the debugger using Android Studio 3.5.1 I can check that I have in my car variable a real car:
car = {Car} _listeners = {ObserverList} () id = 156 shasi =
"FDGFGFDGDFGFD" brand = "Renault" model = "Talisman E1 & E2"
nomer = "FGBFDFG"
But when debugger go to line 78 and I see the _selectedCar value is null

I've noticed that sometimes, the debugger is actually several lines behind the line highlighted by the IDE. So in your example, line 77 may have not been executed yet, even though line 78 is highlighted.
I don't know exactly why this happens - it's a bit quirky and over time you will get to learn which are the lines that the debugger is never accurate about, and which lines are always accurate. For example, a breakpoint on if (true) { will never be hit. For those reasons, I would recommend avoiding manually stepping over/into once a breakpoint is hit. Instead, click to set breakpoints on all the different lines that you are interested in, and resume running.
For your use case I would suggest putting breakpoints on lines 78 and 79. Closing brackets such as line 79 are always hit.

Looks like
selected car = car
is an variable inside a class.
Do you have any async method running in the background?
Maybe someone is changing the value, while you look at it.

Related

How do you add an if statement to a TimerComponent in Flame Game Flutter?

I'm trying to add code to my Flame Game to check if a list isn't empty and if it isn't, then send it to a function. However, I'm receiving an error on the if statement that says "Expected an identifier". How do I change my code to run an if statement here? Additionally, how would I cancel the Timer after it runs?
var instructions = [];
myGame(){
add(
TimerComponent(period: 2, repeat: true, onTick: () =>
if(instructions != null){populateInfo(instructions)}),
);
}
You can use runtimeType, Use runtimeType to get the runtime type.
A property of the Object class, which is the base class of all objects in Dart, and of type Type.
for (final element in gameRef.children) {
if (element.runtimeType == Instructions) {
//my element exist in the scene
}
}
I used the last code for explain the use of runtimeType, but with Dart you have more options like to
children.query<Intructions>();

Unreal Engine 4.27.2 C++ | SetText not updating UserWidget’s TextBlock from a WidgetComponent in a BP

I have an Actor BP, inside this BP I have a UWidgetComponent with a Widget Class already selected in the Details, and that Widget Class has a TextBlock. Now, inside this BP I also have a C++ USceneComponent, this component is in charge of showing a random text, in the TextBlock mentioned above, each time the user presses a button.
This is in my USceneComponent's header file (.h)
class UWidgetComponent* QuestionWidget;
class UQuestionProjectionText* QuestionText;
class UTextBlock* QuestionTextBlock;
Then in the ".cpp" file, in the constructor
QuestionWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("CodeQuestionWidget"));
QuestionTextBlock = CreateDefaultSubobject<UTextBlock>(TEXT("CodeTextBlock"));
Then in the BeginPlay()
//Gets the WidgetComponent from the BP
QuestionWidget = Cast<UWidgetComponent>(GetOwner()->GetComponentByClass(UWidgetComponent::StaticClass()));
if (QuestionWidget)
{
QuestionWidget->InitWidget();
//Gets an instance of the UMyUserWidget class, from the UWidgetComponent in the BP
QuestionText = Cast<UMyUserWidget>(QuestionWidget->GetUserWidgetObject());
this->QuestionTextBlock = QuestionText->QuestionTextBlock;
//Sets the text to an empty String
QuestionTextBlock->SetText(FText::FromString(""));
}
else
{
UE_LOG(LogTemp, Error, TEXT("QuestionWidget was not found"));
return;
}
Then in the TickComponent(), when the user presses the button, I use a something that looks like this
QuestionTextBlock->SetText(FText::FromString(QuestionStringsArray[9]));
The problem is that when I press the button, the text does not change in the Widget, but if I print the text that I'm passing, it does print the string, so I'm not passing an empty value to the "SetText()".
Another weird thing, is that the line in the BeginPlay that sets the text, that one works, I have changed it to a random string, instead of an empty one, and it does display it.
I don't know if when I do the "QuestionWidget->InitWidget();" I'm creating a new one separate from the one in the BP, or if I'm just missing something. If I eliminate the "QuestionWidget->InitWidget()" the widget gets initialized on time sometimes, and sometimes it doesn't.
I have some error handling in my code, but eliminated it here so that it didn't look too messy. But also, none of the Errors popup, everything goes on smoothly, only that the Widget doesn't show the updated Text.

MS Word VSTO Addin Find.Execute fires ContentControlOnEnter event

It seems that if Find.Execute finds a result inside a ContentControl, it will cause the ContentControlOnEnter and ContentControlOnExit events to fire. It's particularly annoying because the exit event fires even if the selection is still in the content control, so any code which sets the states of buttons dependent upon a content control being active will appear to be in the incorrect state.
Given a document containing a single content control with the word "test", and the following code:
// In setup
Application.ActiveDocument.ContentControlOnEnter += ActiveDocument_ContentControlOnEnter;
private void ActiveDocument_ContentControlOnEnter(Word.ContentControl ContentControl)
{
var selRange = _Application.Selection.Range;
_logger.Debug(m => m("Selection: {0}-{1}", selRange.Start, selRange.End));
}
//Later in another method
var finder = _Application.ActiveDocument.Range().Find;
_logger.Debug("Find.Execute start");
finder.Execute("test);
_logger.Debug("Find.Execute end");
The following gets logged:
38137 [VSTA_Main] DEBUG - Find.Execute start
38141 [VSTA_Main] DEBUG - Selection: 1-5
38149 [VSTA_Main] DEBUG - Find.Execute end
We have a lot of code that handles ContentControlOnEnter and ContentControlOnExit events, and having the find operation cause them to be called is really causing problems!
Is there any way to use Find.Execute without having it trigger these events? Failing that, is there a good way to distinguish between the Find-triggered ones and the genuine user ones? I have tried using the time between the enter and exit events, but this is not reliable.
I had similar problems in Word, though it was about the Selection event. I tried many solutions, but only one helped. In your case, make a new field bool _skipEnterAndExitEvents and set it true before calling
finder.Execute("test) and false after calling. And in the enter and exit event handlers check this field, if the field is true then just skip. This solutions is not beautiful, looks like a hack, but other solutions are even uglier and don't really work.
I think I found a decent solution:
private bool _doIgnoreNextExit = false;
private void ActiveDocument_ContentControlOnEnter(Word.ContentControl ContentControl)
{
if (Application.Selection.Find.Found)
{
_logger.Debug("Ignoring CC enter event caused by Find operation");
_doIgnoreNextExit = true;
return;
}
// Do things
}
private void ActiveDocument_ContentControlOnExit(Word.ContentControl ContentControl)
{
if(_doIgnoreNextExit)
{
_logger.Debug("Ignoring fake exit");
_doIgnoreNextExit = false;
return;
}
// Do things
}

Calling methods on datasource in displayoption lags screen and prevents records from showing

I have overridden the displayoption method on my forms datasource to display lines in red which don't have enough stock (based on stock position & released production orders) but I think calling several methods on the datasource (which are also used by display fields on my form) has such an impact on the drawing of my form that the lines are red but the data isn't shown:
public void displayOption(Common _record, FormRowDisplayOption _options)
{
ProdBom _prodbomlocal = _record;
if (this.DRS_GetLineAvailable(_prodbomlocal) < 0)
{
_options.backColor(8421631); //Light Red
}
}
For instance when there are a lot of lines for which available stock, released production quantity, etc needs to be queried only one line is shown instead of e.g. 30 lines
I don't know what to do, is there some way I can pre-query the data?
Kind regards,
Mike
Have you tried calling the super()?
Any computation in displayOption should be very fast, or your form will suck.
Do not use color code in decimal, at least use hex 0x8080FF (BGR code).
public void displayOption(Common _record, FormRowDisplayOption _options)
{
ProdBom _prodbomlocal = _record;
if (this.DRS_GetLineAvailable(_prodbomlocal) < 0)
{
_options.backColor(8421631); //Light Red
}
super(_record, _options);
}

DWT togglebutton: does it even work?

I'm not sure if we are just 20 people in the world using dart right now and maybe just 10% of us try to use widgets..anyway, I seem not to understand if I'm doing something wrong with DWT or there is a bug. Here is a very simple example. I don't understand why the event are not even fired.
void main() {
ui.HorizontalPanel panel = new ui.HorizontalPanel();
ui.ToggleButton t1;
t1= new ui.ToggleButton.fromText("click",handler: new event.ClickHandlerAdapter((event.ClickEvent e) {
hans(panel,t1);
} ));
ui.ToggleButton t3;
t3 = new ui.ToggleButton.fromText("click");
t3.addClickHandler(new event.ClickHandlerAdapter((event.ClickEvent event) {
window.alert("Stop poking me!");
}));
panel.add(t1);
panel.add(t3);
ui.RootLayoutPanel.get().add(panel);
}
void hans(ui.Panel panel,ui.ToggleButton button){
var iter = panel.iterator();
while (iter.moveNext()) {
var butt = iter.current;
if (butt is ui.ToggleButton){
if (butt != button) {
butt.setDown(true);
}
}
}
Not really an answer to your question, but something I've noticed:
Not sure if bug or by design, but seems like the first node of a Tree does not handle clicks properly. I've created a tree with two ui.Label(s) in it and the first ui.Label does not respond to clicks. No aparent reason for that.
If I insert these ui.Label(s) in reversed order the situation is still the same: the first ui.Label (the other ui.Label, this time) does not respond to clicks.
So, I've circumvented the trouble by adding a Label in the beginning as "/" which is absolutely useless but does not need to respond to any clicks anyway.