I'm trying to do a "show item info in widget on mouse overlap" thingy, and it works so-so. It seems that the OnBeginCursorOver/End fires continuously, causing the widget to flicker (on, off, on, off....)? Now, if I disconnect the OnBeginCursorOver, OBCO fires once and the widget shows fine. Of course, it is no longer removed.
Its a very simple setup. Widget Visibility is BOUND to a BOOL on my Player Character which I toggle TRUE on OBCO, and FALSE on OECO.
Anyone?
Turns out it had to do with visibility settings. Works fine now.
Related
I'm trying to use toggles on an inactive screen as a replacement for functions (and thus help code reuse), however I'm stuck as my toggle won't activate unless I visit the page it's on. I found plenty of working examples online but somehow can't get it to work for me.
Overview:
I have a button on screen1 and a toggle on screen2.
During my button's OnSelect event, a variable varSendData is being set to true like so:
Set (varSendData, true)
The toggle has its Default property set to varSendData.
The OnCheck property of the toggle contains the code to be executed:
Notify("This works")
Problem:
While the variable varSendData is correctly being set to true, nothing happens while I'm on the screen1 with the button. Only when I visit the screen2 with the toggle (even if in edit mode only) does the toggle change state and execute the code in the OnCheck property. I tried using the OnChange property of the toggle, however that has the same effect/limitation.
Furthermore, if I set the variable (varSendData) back to false before visiting screen2 then nothing happens from which I conclude that the toggle is only triggered (changed) if the page it's on is visible/active.
Any ideas on how I could get the toggle to change state even if I'm not screen2? Or any other ideas on how I could reuse the same code from different screens?
It's a limitation of the method the actual code is calling. In order to allow the HTML to refresh from this "Notify("This Works"). You would need to also have a function that refreshes the HTML in the screen your currently viewing.
I was able to get this to work by adding a label and setting its text property to be If(Toggle6.Value = true, "yes", "no").
Literally adding this in allowed the notification to pop up. Nothing extra.
I have a sample code which detects a hovering stylus over a widget.
The code is from this Stackoverflow Quesion.
In short. It binds using GestureBinding.instance?.pointerRouter.addGlobalRoute and checks in the handler if the event is of type stylus.
This gets triggered when the stylus is hovering over the screen (no contact).
It works great on Widgets like Text(), Container() etc.
Question:
I want to use this functionality on a different Widget, the Flutter InAppWebView but the event will not get triggered until the pen has contact with the surface. Even on the Container it does not work, if the child is the InAppWebView.
I think this problem will occur on other Widgets too.
I tried the Listener, AbsorbPointer and IgnorePointer.
Update 1:
I can see the following in the debug output when I start hovering the stylus over the screen.
I/ViewRootImpl(23491): updatePointerIcon pointerType = 20001, calling pid = 23491
D/InputManager(23491): setPointerIconType iconId = 20001, callingPid = 23491
Update 2:
The InAppWebView has an option useHybridComposition which is false by default. Setting it to true solves the issue. But the WebView is becoming very slow.
HERE is a repository that shows the problem.
Thanks!
EDIT
As desribed below, this question has two solutions.
Set useHybridComposition to true. For slowness, maybe raise an issue to that repo.
Hook at android/ios level instead of Flutter level, and forward events back to Flutter.
The debugging method maybe like this: Firstly, print out the pointer events in methods like your _handleEvent. Then you will know whether the pointer event just occur, or they even do not occur.
Secondly, try what widgets are OK and what are not. Text is OK, WebView is not. Then is Container OK? Is InkWell OK? Is IconButton OK? Is IconButton OK? etc. By doing this you gain insight of what is special about Text that makes it work.
Thirdly, as a hacky workaround, could you please try Text.rich(WidgetSpan(child: your_web_view))? Since you say Text is OK while other widgets are not OK.
Lastly, maybe need to dig into Text's source to see what magic happens - probably some special configuration? - to let it work.
I am employing Riverpod for state management via StateNotifierProvider. My switch button just won't enable upon clicking and thus no state changes to effect theme mode switching. I have spent a ton of hours researching similar issues but none like mine as I am not using setState(). I expect the state of the button to change on clicking on dragging but the thumb of the switch just returns to its initial off position. Please help me with what I am doing wrong. Here are snapshots of my main.dart, home_screen.dart, and the theme controller notifier as I am unable to copy and paste my code correctly as advised with 4 spaces.
You need to update the state (not the _isDarkvariable) this way:
toggleTheme(bool value) {
state = value;
_safePrefs;
}
The image is not complete, so I can't see the use of _isDark variable (Probably nothing). But You shoul be fine now, at least updating the state.
I have two app 'screens', A and B. Both set the SystemChrome.setEnabledSystemUIOverlays in the build methods.
A sets as per
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
return WillPopScope(
....
whilst B sets as per
Widget build(BuildContext context) {
if (MediaQuery.of(context).orientation == Orientation.landscape) {
SystemChrome.setEnabledSystemUIOverlays([]);
}
else {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
}
return WillPopScope(
.....
Navigating from A to B in portrait works fine. If however I enter landscape in B flutter removes the overlays and then re-implements them immediately, ie I see the overlay disappear and reappear quickly. If I remove the overlay line completely from A, B works fine. Its like B is rebuilt followed by A but in the background. Is that a thing?
I'm navigating like so
Navigator.push(context, MaterialPageRoute(builder: (mContext) => DataForm(file: _file)))
I've been tying to track this bug for three days. For reference overlays are set here an only here in all my code. The issue only occurs on Android.
I appreciate the first response will be 'its in your code we need to see it to solve it'. I tried reproducing the issue in 'minimal code' to post an example but I cannot get the error to reoccur and my code is so extensive I am not sure how to show it all.
As per the title I am instead asking what scenarios might cause screen A overlay setting to influence screen B at each build.
Thanks in advance!
Answering my own question after 5 days of tracking down my bug in the hope it might help some else if future. I suspect those with experience will be thinking 'yes of course and' so this is probably more for someone new like myself.
SystemUIOverlay is like a global variable that persists in the app and is implemented across screens automatically. A new screen/code can change this overlay setting at any time and know if will be applied globally and retrospectively to all screens. In my case SystemUIOverlay is set in build so any action in Screen A that forces a rebuild will therefore enforce the update and apply the global overlay value to B.
Even though Screen A is not showing it can continue to rebuild in the background if triggered, even when Screen B is opened. Therefore anything triggering a rebuild of A whilst B is open means B will adopt A's overlay setting globally. This was the result I was seeing.
A couple of examples:
As referenced here, MediaQuery.of will cause your widget to rebuild automatically whenever the MediaQueryData changes (e.g., if the user rotates their device). So for instance if you include 'MediaQuery.of' anywhere in you build of Screen A, a build can occur even when not in focus. This rebuild of A then enforces it's overlay value globally which is picked up by B whilst it is open.
In my case rebuilding B set the overlay to [] and affected the insets. MediaQuery in A picked up on this, rebuilt and reset the overlay to .values and forced these onto B. And round she goes.
A periodic timer calling setState in A will do the same thing. I am sure there are many more examples.
So look out for and avoid any rebuild potential in A when it has lost focus.
I want to push toolstripbutton down in my code and I can't seem to be able to do that. I know on Delphi RAD Studio or XE, you can do the following and cause the button to be pressed.
ToolStripButton1.Down := true;
The only ToolStripButton property I see that comes close to "down" is checked true or false. If I do set it to true, it only highlights the toolstripbutton not press it down.
Here is how the button looks when I put my mouse on it and click:
You can clearly see that the Zoom In button is down.
Here is how the button looks when I try to do the samething through my code by setting CheckOnClick true and Checked true.
In this image, the only thing you can see is the blue box around it. I suppose if I had used just the text on the button, you will see that the whole button filled with blue color to show that it was pressed.
I also have toolstrip button in my other program which acts the same way but I had to use imagelist control to switch between pressed or down or checked verses not pressed or down or checked.
So, is there a way to press the ToolStripButton programmatically in Delphi Prism or C#?
Set the ToolStripButton.CheckOnClick property to True. (It's found in the Behavior section of the Items Collection Editor.)
This makes clicking it just like toggling the Down property in a Delphi TSpeedButton (making it flat or depressed), and if ToolStripButton1.Checked is the equivalent of if SpeedButton1.Down in Delphi.
To set up the test, I did the following:
Created a new Winforms application
Dropped a ToolStrip onto the new MainForm
Added four ToolStripButton items and gave them images to make them easier to see.
Set the CheckOnClick property to True for each of them
Set the Checked property of toolStripButton1 to True;
Added the code below to toolStripButton1.Click
method MainForm.toolStripButton1_Click(sender: System.Object; e: System.EventArgs);
begin
toolStripButton2.Checked := not toolStripButton2.Checked;
toolStripButton4.Checked := toolStripButton2.Checked;
end;
Running the app (initial startup, toolStripButton1 checked and the others unchecked):
The first button is clearly down, and the rest are up.
After clicking toolStripButton1 once:
The first button is now up (unchecked) and the second and fourth are down (checked). (I should pay more attention to the consistency in sizing if I do successive images in future posts.)
If have placed this code in the preceding control in the 'Leave' event.
Private Sub PurposeComboBox_Leave(sender As Object, e As EventArgs) Handles PurposeComboBox.Leave
Me.AppliancesForSelectedFunctionToolStripButton.PerformClick()
End Sub
I do not know if you could place code in Form Load or not.
Hope this helps.