When changing theme to Darkmode with GetX via Get.changeThemeMode(ThemeMode.dark), most widgets change accordingly. But those widgets using some parameter with Get.theme need a hot reload for the effect to take place.
As a comment suggested here, that is because Get.theme is immutable. Using the extension method context.theme does resolve the issue, however, I do not always have access to a context. Get.context.theme does not resolve the issue. What should I do in this case? Since passing the context to wherever needed kinda defeats the purpose of using GetX.
I am not sure what 'some parameters' you are talking about since you didn't include any code, but you can use the Get.changeTheme() method which takes a ThemeData object and changes the theme accordingly without hot restart.
Related
I have 4 widgets named OptionCard (it's their Type) i'de like to iterate through them to check the value of their variables how can I do it ?
tried OptionCard.forEach but it doesn't work
This is not the way Flutter widgets are supposed to be used. Widgets (even StatefulWidgets) generally do not hold application state. They should only provide a view on state managed elsewhere.
There are many proven methods of application state management that are popular and well supported in Flutter.
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 new to flutter in one of my project pages set state doesn't work at all no matter what I do I tried every almost everything every time doesn't work so what think can stop set state from working?
note: I am using provider and shared preference
setState(){} only works in StatefulWidget class, I think you are using StatelessWidget. If you want to use it change your class to StatefulWidget.
actually, nothing can stop it from working, and because you are new I am inviting you to accept that there is not something wrong with flutter but with your skill in flutter.
if you provide some code we might be able to help
I wrote a package for Flutter and added it to the main.dart and it works well but How can I access the value of one of the variables in the package? or how return a variables from it ? For example, in the slider widget, we have access to the value of the slider with on change .
You want to learn how to manage state in flutter.
There are couple of good state management tools:
provider seems to be the easiest one.
Here is a nice tutorial on provider:
https://blog.codemagic.io/flutter-tutorial-app-arhitecture-beginners/
I understand the general approach to building UI layouts using Flutter. However, I'm still unclear which classes or UI widgets require a .build() method when I'm creating my own vs. using the defaults generated by the project.
I haven't found a clear explanation yet - even in the Flutter tutorials. They all seem to just gloss over how "the build method takes a BuildContext" and then go on to the next subject without explaining further.
Does anyone have a succinct explanation of the build method and when it is or isn't needed? And more specifically: what does it actually do?
build() method describes the part of the user interface represented by this widget.
The framework calls this method in a number of different situations:
After calling initState.
After calling didUpdateWidget.
After receiving a call to setState.
After a dependency of this State object changes (e.g., an InheritedWidget referenced by the previous build changes).
After calling deactivate and then reinserting the State object into the tree at another location.
You can find more Here
TLDR: The build methode is used to create a new widget tree by placing the Widget reurned in the page tree. This method is essentially called when you create or update the widget (by calling setState((){})