How to recreate a TextField widget with my own behavior? - gtk

I would like to create a test application with PyGTK.
My goal is to create a textfield widget 100% customized. Indeed, I would like to fully change the default behavior of a textfield widget.
Is it possible to fully change the behavior of a textfield (like shortcuts/keymaps, scroll behavior, etc.) ?
Is it possible to recreate the widget from scratch ? If yes, how can I do that ?
Thanks.

Are you referring to a gtk.Entry or a gtk.TextView?
In any case, you are going to want to subclass the widget you want to customize and override any methods that you need to change. If you can read C code, that would be helpful as you can look over the widget source code. If you've never written your own widgets, you might want to start with a tutorial like http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/

Don't recreate it from scratch. Derive from it instead and overload what you intend to change.

Related

how to exclude a widget from setState?

I am designing an application that uses setState to refresh a screen with all its widgets, however I would like to know if there is a way to exclude a particular widget (conainer) and all its children, as if I were treating it as a new page.
I tried to use Navigator.push (context, MaterialPageRoute), but it didn't work, I would like to treat the widget as a separate page. I appreciate any help
Short answer: You can't.
Long answer: You can change where the setState is called, create a separate StatefulWidget that contains only the ones that need to be rebuilded. However in most of the cases this is not possible because of the order you need to show your widgets or many other factors. That's when State Managements tools come in handy. You should try to learn how to use Provider, Riverpod or BLoC (which i personally recommend). If you want something a litte bit easier you can start learning how to use InheritedWidget starting in the documentation right here.
use const if possible. if not,
use StatefulBuilder , if you call setState inside this widget, the outside widget is not touched. Maybe it will suit what you need

What is the best practice to improve performance?

I'm newly learning and creating simple app using flutter.
I created drawer inside Scaffold for some pages and I got confused if when I click the ListTiles, should it be routing the pages or just switch the body widget using setState().
I guess setState() must perform better but I'm not sure if this is a good practice for pages. If it does not have a big difference in performance, I would like to use routing the pages since it will be uniformed.
Personal opinion:
Avoid separating widgets into functions, use StatelessWidget instead. Cause every render function will rebuild whatever parameter changes.
Avoid using setState as much as possible, especially for large Widgets, instead use provider, get or simply use ValueNotifier if you dont want library. Cause setState will mark all things to be rerender include widgets that not need to be rerender.
Do not render too many things at once, if possible only render the views that are / are about to be displayed. Example using ListView.builder instead of ListView, ... etc
With image, please resize to suit your needs, a 2000x2000 image loaded as a 24x24 icon is clearly not a good idea.
using const.
I'd suggest to redirect user to the next page as it won't require a StatefulWidget (you can use navigator to navigate user to another activity) which will be lighter to run, as if you use IndexedStack or dynamically assign the widget it'll require the StatefulWidget..

How to check visibility of a Flutter widget even when covered by another

I'm trying to find a way to check the visibility of a Flutter widget when it's either off screen or when it's obscured by another, for example Drawer, Dialog or BottomSheet.
visibility_detector helps with checking whether it's on the screen or not but does not work with the second use case (known limitation).
Is there a lower lever api that I can use to check whether a widget is actually visible to the user?
My use case: I'm adding a widget to the Overlay when something external happens (similar to Tooltip but not on long press). If the user opens for example the Drawer, the widget will appear on top. I want to detect that the child is not visible and delay or cancel the action.
Do I understand your problem?
You have a widget you want to always be on top?
You want the user to interact with that widget first before doing other things?
Use design patterns to make coding easier, your users will thank you.
You can show a Dialog on-top of other widgets with the showGeneralDialog or showDialog functions. Because Dialogs are a design-pattern used in many apps, users will already know how to use them.
Define app behavior with explicit state.
It is too hard to derive app behavior from rendered UI, not all devices are the same size and shape. This means you should try to write a variable that describes your situation and then write the code you need to make that variable's value correct. It sounds like you want a variable like bool overlayIsShowing.

Best way to implement Material expandable input chip in flutter?

I'm trying to figure out a way to implement the "expandable" behaviour illustrated in https://material.io/design/components/chips.html#input-chips.
I've dismissed using a combination of Stack+Positioned & AnimatedSwitcher, since this would require inserting the input chip at the scaffold's top level, when it's initial position should rather be determined exclusively by it's actual parent (e.g. a wrapping row). Everything else seems to contradict flutter's "overflow is evil" rule, however.
Any ideas?
I was unaware of the Overlay widget's existence and have built my implementation based on that.

Is it possible to add/inject an instance of a Widget into many panels?

I've tried doing this but only one panel gets the Widget shown. What is the approach to add an instance of a Widget into many panels? Or is it even possible?
If by inject, you mean use some DI tool (like Guice), then yes, you can inject the instance into many other instances as a singleton (just like any other singleton).
However, a given Widget can only be rendered in one place at a time. Elements can be cloned, but there is no general method of copying a widget to draw it in more than one place, mostly due to all of the event handlers that have to be added again.
How would then this method work?
Widget getParent()
Gets this widget's parent panel.
So you have to create multiple instances. Btw what's your use case?