Can I disable the automatic keyboard pop-up of the SearchDelegate Class? - flutter

Im using the SearchDelegate Flutter class. It automatically opens the keyboard when I use the showSearch Method.
I figured that I could close it right away within one of the overwritten Methods. But I don't want it to pop-up in the first place. Only when taping the search bar.
I know that the SearchDelegate class has a _focusNode attribute but I don't know how to work with it.
Any ideas? Thanks in advance.

As of today (december 2022), going strictly by your question : no, you can't.
Dart fields with a leading underscore _ are not just a naming convention, they allow to mark fields as private. Such fields will only be available to :
The declaring .dart file, when declared at top-level.
The parent Dart object, when declared at scope-level.
Thus, your code does not have access to the _focusNode field, nor the _SearchPageRoute<T>, _SearchPage<T> or _SearchPageState<T> classes.
In conclusion, you can either deal with this limitation or create your own custom implementation of this search page. You could either build it from scratch, or by forking the existing showSearch implementation and modifying it to fit your needs.

Related

Flutter Refactoring move widgets to new files

I have a DefaultTabController that is getting longer and longer in code. As a beginner, I see I might miss some class / oop knowledge here.
I want to move its children to new files. I already have Widget TabContent1 and Widget TabContent2 in the same class, but how can I move these widgets to new files? The problem is that they both load values of TextEditingControllers on the TabController level. Moving the two Widgets breaks the reference to these TextEditingControllers. How can I refer to those from the newly created classes?
Update: In addition. As suggested by Ivo, I can put all references in the constructor of my new class. But I have a lot of global controllers and variables in the top level class. Also need to bind to the events happening in my new class and have to emit those back or so. It feels more efficient to keep my logic, but only move some of it to sub-classes or so. I feel like the solution should be more in oop/class logic, implementing or extending them

How to make IntelliJ IDEA highlight the implemented methods of an interface

In Eclipse, when I put the caret on an Interface a class is implementing, the methods are marked in the side bar by default (as small colored stripes). This way I can easily see the methods the class is implementing without having to go into the interface itself and check out what methods it contains
I haven't found anything similar in IntelliJ. Is this even possible somehow easily?
(As a side note, I use Kotlin when programming, but I assume that this feature is not found for Java either)
In Java, you can put the caret on the "implements" keyword and press Ctrl-Shift-F7 to highlight methods implemented via an interface (if the class implements multiple interfaces, you get a popup asking you which methods to highlight). An equivalent feature for Kotlin is not implemented at this time (as of Kotlin 1.3).
In the class body, you can indeed see the interface methods highlighted by gutter icons, as the other answer says.
Methods or properties that are overriding or implementing anything of a parent class or interface are marked next to the line numbers, finding out from which class or interface they are coming can be done by hovering over them:
Clicking on it will take you to the parent/interface definition.
The same mark, but with a downwards pointing arrow, is used in the interface/parent class and shows a list of implementations/overrides when clicked on.
All of this also works for java and scala.

Order of evaluation with relative layouts, best practices and parsing of relative-layout

I read this
"
It used to be that Android would use a single pass to process
RelativeLayout-defined rules. That meant you could not reference a widget
(e.g., via android:layout_above) until it had been declared in the XML. This
made defining some layouts a bit complicated. Starting in Android 1.6,
Android uses two passes to process the rules, so you can now safely have
forward references to as-yet-undefined widgets.
"
I do not know what is the problem maybe is eclipse problem, but even I use 2.3 I still have problems when I reference some view that is not declared jet so for me it seems like android doesn't uses two passes to process the rules for relative layout.
note: I always use #+id/widget_name when I declare the widget and #id/widget_name when I reference that widget from other widget. I have noticed that I can use #+id/widget_name even when I just want to reference that widget. I guess that is wrong but why sometimes is works without any complaints ? In my opinion one widget should be allowed to be declared only ones...
My questions is is really android uses two passes ? and I need some guidelines (best practices) for working with relative layouts
I am little confused about how this relative layout parings are made, so any explanations are welcomed
Thanks
#+id/name creates a new id, if it doesn't already exist. #id/name references an existing id, and will never create one.
I'm not sure if you can use #id/name before #+id/name in the same file. If not, I can think of two workarounds:
Always use #+id/name.
Define all id's in the ids.xml file, and always use #id/name.
This is general information on how Android draw views.
I think that Android passes twice through all the view, but it doesn't pass through each single view once. So if you have a reference from one xml to another it will always work fine, but if you have references inside a single xml you must be carefull to order the elements in the xml correctly. For example, I have view1 and view2 in my RelativeLayout. If I want to refer to view2 from view1 I must declare view2 before view1.

xcode dropdown - shows all my class properties and methods. Just want methods

Not sure what to call it, but in xcode there is a dropdown that lists
all the properties and methods in the current file.
Is there a way to just show the methods? I have a few classes with a boatload of properties, and having to scroll past them in the dropdown is a pain.
Thanks!
No, You cant hide your properties from the drop down list. It is for showing methods and properties both. so if you think you take more time to find the method then type one or two letter : list will be automatically sort.
Xcode Plugin for hiding properties in dropdown list https://github.com/shpakovski/Xprop

GWT use of interface instead of widget

in a définition of a widget, what is a better practice, and why, use the widget himself or the type "higher", example, it's a better practice to do
1) Button myButton;
or
2) Hastext myButton; (and set a button later)
thanks for your answer.
It is usually a good idea to use "higher" types or interfaces. By doing this properly you can hide implementation details. The code that uses an object looks at it as the one of a higher type and it is not important what is actually hiding behind it. This is good because you can easily change an implementation of the object without breaking anything.
For example when defining a panel in an application you should use Panel class instead of its implementation e.g. HorizontalPanel or VerticalPanel.:
Panel myPanel;
Then you can create a proper implementation of it, e.g HorizontalPanel:
myPanel = new HorizontalPanel();
If you then later decide to change myPanel to be VerticalPanel you will not have to change anything in the code that uses myPanel. Everything will work just fine.
However you must remember that you will be only able to use methods available in Panel class. Additional methods defined in e.g. HorizontalPanel will not be accessible. And this is actually what you should remember when choosing the type of your widgets. Your widgets should be of types which provide methods which you want to use.
In your example using HasText instead of Button isn't probably a good idea because HasText has only methods for setting and getting a text and you probably also want to have access to addClickHandler method available in Button and a few more.
So to summarize it is good to use "higher types" but they should not be "too high" to be useful.
The answer to that lies in the Model-View-Presenter pattern, that was introduced in last years Google IO presentation by Ray Ryan. There's also an official tutorial/docs - part 1 and part 2. There are also a number of questions here on SO that cover that topic :)
And a quick answer to your question (that will make more sense once you get familiar with MVP): use interfaces in the Presenter and their implementations in the View :) That way your Presenter stays oblivious to the underlying implementation/Widget you actually used (was it a Button? Or a Label? It doesn't matter, they both implement HasText).