Keep keyboard open on page and disable every close option - flutter

I have an app with 2 pages. The first page is the main menu, and when you navigate to the 2nd page, a keyboard open himself inside a TextField (autofocus).
What I want to do is disabling every ways of closing the keyboard. Right now, it doesn't close when you submit, but that's the only thing I achieved to do.
The user can still close it with every other ways (in my case, it's the android navigation bar who has the left button who can dismiss it).
Is there any ways to keep the keyboard open during the whole time an user stays on a page?
EDIT:
I found this package : keyboard_visibility to do that inside initState:
KeyboardVisibilityNotification().addNewListener(onHide: () {
setState(() {
FocusScope.of(context).requestFocus(_focus);
});
});
Each time I hide the keyboard, onHide is called and I can execute some code. Here I try to focus the TextInput again to re-open the keyboard immediately. When the keyboard is hided, the function is called, but requestFocus doesn't seems to work.

Try this,
FocusScope.of(context).requestFocus(FocusNode());

Related

Implementing a menu in SwiftUI without the Back/Cancel button

I am currently working on a project for watchOS that involves the creation of a new menu using SwiftUI. The issue I am encountering is that the new menu always displays a 'Cancel' button in the top left corner of the screen. This button allows the user to leave the menu, which I do not want to happen.
WatchOS Simulator displaying the cancel button
Button(action: {
self.showRide = true
}) {
Text("Start Ride")
}
.sheet(isPresented: $showRide) {
StartRide()
}
To address this, I would like to remove the 'Cancel' button from the screen and replace it with a custom button. I understand that there will be an 'Exit' button available in the view later on, but I would like to have more control over the user experience.
Is it possible to achieve the removal of the 'Cancel' button and replacement with a custom button in this scenario? I am eager to find a solution and would appreciate any help or guidance offered.
I initially attempted to use NavigationLink to open the new menu, however, it was not successful. Despite my efforts, the menu simply would not open. As a result, I decided to stick with my original code. While this solution may not be the most ideal, it has proven to be functional in opening the menu as intended. However, the main issue with my original code is the presence of the 'Cancel' button in the top left corner of the screen. I would like to remove this button and have more control over the user experience within the menu.

Softkeyboard's "check" button vs using .unfocus()

In this video I first click on a field within the first tab, then click the soft keyboard's "check" button. This hides the soft keyboard and takes the focus away from that field. I then navigate across tabs and back to the first. No field has the focus at this point. This is the expected behavior.
In the second iteration, I click in the notes field. Without closing the soft keyboard, I then click the submit button. That button calls FocusScope.of(context).unfocus(); which hides the soft keyboard and takes the focus away from the notes field (the teal border disappears). However, at this point I click on the next tab and the soft keyboard reappears. And when I click back the first tab the notes field once again has the focus.
Why does this happen?
What underlying code does the "check button" on the keyboard call and can I wire this up to the button rater than calling the .unfocus() method to get the expected result?
Edit: Still no explanation. The undesirable persistent keyboard does not occur on iOS.

Flutter Clear Search Text Persists Search

I have a Text Field with _searchController and a separate IconButton that clears the _searchController:
_placesList are the search results.
I also have a method _onSearchChanged that is a listener for the _searchController:
The _onSearchChanged method calls another method that makes an API call if the search controller is not empty:
When the cancel icon button is pressed, I found (through debugging) that the search controller listener is triggered before the search controller text is cleared and therefore an API call is made and THEN the search controller text is actually cleared.
This leaves a list of unwanted search results on the screen.
Hitting the cancel icon button a 2nd time results in the desired outcome of clearing the search results. But obviously I don't want the user to have to press the cancel icon button twice.
I want the cancel icon button to clear the search text and the search results.
I believe you are missing setState here.
Simply wrap the _searchController.clear(); in it like tihs:
setState( () {_searchController.clear();} );
Otherwise flutter won't rebuild with the new data.
This is a common mistake that people forget about.

How to close Dialog using FlutterDriver

Is there any way to close a dialog by "tapping it away", i.e. tapping outside of the content to close it with Flutter Driver?
My problem is that the dialog does not have any buttons that would close it. Instead the user is expected to either tap outside of it or use the back button. However, FlutterDriver does not have a "back" option.
Hence, I am wondering how I would tap outside of the dialog in order to close it.
The key that is commonly used for modals in Flutter is ModalBarrier, which is why the following should do the trick:
await driver.tap(find.byType(ModalBarrier));
This will work as long as barrierDismissible is set to true.
Essentially, when tapping away a dialog in Flutter, you are tapping on the modal barrier, which is why above code works.
Thanks to John Muchow for finding out.
You would want to set the barrierDismissible property of the dialog to true and add a barrierLabel.
This will allow you to tap outside and close the dialog
https://api.flutter.dev/flutter/widgets/showGeneralDialog.html

Show popup/window in a gwt tab

Is it possible to show a popup only in a certain gwt tab or a panel in that tab?
I've found methods to show a popups over the whole page, but not only in specific tabs.
When you switch the gwt tab, the popup should not be visible anymore and new popups should be able to be created, which again are only visible in the switched to gwt tab. Switching back to the other tab should then show the first popup again.
Optionally the rest of the tab, which is not covered by the popup, should not be clickable.
Are there any native methods for this? The gwt Popup Panel only seems to create popups for the whole page.
Edit: I've tried using smartgwts Window which seems to work just the way I want it to. When I switch the gwt-tab, the popup is no longer visible and returns when I switch back. The only problem is, that it isn't displayed right. The frame is placed on the far left side of the browser tab, while the content is displayed on the far left of the gwt-tab. If I move the content, the frame moves too. The frame is visible over the whole browser tab, while the content disappears if I drag it over the gwt-tab edge.
I guess it's because I'm adding a Window to a gwt-Panel. Is there any way to fix this without changing everything to smartgwt?
Not exactly, I think.
But, you can do something in the tab events, like hide the popup in tabs that it doesnt belongs. To avoid the lag of show/hide the popup, you can do this in the BeforeSelectionHandler, like this:
getView().getTabPanel().addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>()
{
#Override
public void onBeforeSelection(BeforeSelectionEvent<Integer> event)
{
showPopupupsForTab(event.getItem());
}
});
In showPopupupsForTab you can show the popups for this tab (you can handle this with a map or something) and hide the others...
Something like this.
Hope it helps.