In my code, I have firebase auth and I get the current user as:
User user = FirebaseAuth.instance.currentUser!;
To display the user name in a Text, just use Text(user.displayName)
To test the update functionality, I created a simple button and on onPressed I have
user.updateDisplayName('Test').then((_) =>user.reload());
How to "notify" the Text that the data has changed and change it without needing to reload the simulator?
--> this code is in a drawer
Since you're using Flutter, you'll need to store the value you want to re-render in the State of a stateful widget, call setState() when the value is updated, and then render it from there in your build method.
I recommend checking the documentation on StatefulWidget for an example of this, and more explanation than I can ever repeat here.
Related
I'm trying to have the user put information in a TextField on one screen and then save that info when they press "Save". Then I want this text to show up on another screen in another Container (say it asks for their name, they put it in the TextField, press the Button called "Save", it takes them back to the other screen, and the box that previously said "Name" now says "[The name the user entered]").
Thank you in advance for any help!!
Use StateManagement Libraries like flutter_bloc,provider,mobx, getX.
This way you will be able to save your data and use in in any part of your app
There are multiple ways of going about doing this.
You can pass the value through the constructors of the screens you're navigating to (for e.g.
MaterialPageRoute(builder: (context) => NewPage(name: nameValue))
If you want to use this value in multiple places in your application, you can consider storing it in a config class of sorts (i.e., create a class Config as a singleton (only once instance allowed), and store the name there while saving like
Config.name = nameValue. Then, anywhere in your app, you'd access it as Config.name)
If you want this value to be used anywhere else in the app, but also want it to be persistent, then it's probably best to store it as SharedPreferences or in a database. Look into the sharedpreferences package, or sqflite package for Flutter.
Iam using EventChannel to handle events from hardware barcode scanner. EventChannel is initialized in initState, in main class - it works through whole app. While change is detected, it inserts value into global variable (ValueNotifier - i dont know, if it is right) and then I need to work with that value in multiple widgets. I need some sort of widget, which will tell me, that value updated and it will trigger onEvent function - something like RawKeyboardListener. I tried using listeners, but when i do pushNamed, the listener is still listening and it runs code from previous pages, while scanning.
Is there any widget, that would be suitable for me? (cant use ValueListenableBuilder, because it has no "onEvent" function) Or is there any way, to remove and add listeners while moving between pages, or while modal bottom sheet is opened? (I need to access previous listeners, after Navigator.pop)
I solved my problem by using listeners and ModalRoute.of(context).isCurrent.
I'm a new Flutter developer and I have a problem, which I haven't been able to solve yet, even if I tried a lot.
I'm developing an App, where at some point a Dialog is opened(with showDialog()). In this Dialog there are 2 AutoCompleteTextField:
In the first one, the data will always be the same. So there is a list and the user needs to choose one of the choices. First AutoCompleteTextField code
In the second one, the data to be shown depends on the previous choice. In other words,
whenever an item from the previous list is chosen, the subdata of the item will be requested. Second AutoCompleteTextField code
The required data is fetched properly, however the dialog is not refreshing state so the suggestions of the second AutoCompleteTextField appears empty. When I close and enter again the suggestions of the second appears as they should.
To get notified when the data changes I use ChangeNotifier and Provider, but doesn´t refresh the Dialog (ChangeNotifier class). I also use StatefulBuilder to be able to use setState, but again, doesn´t refresh (Dialog code).
I would like to know if there is any other way to refresh the Dialog. Thank you!
PD: This is my first question in StackOverflow. I tried my best.
I think you need to use Provider.of(context) to be able to listen to the updates and refresh or add/update the data.
Provider.of(context)
I would create a widget class instead of the _widgetTask function and then use Provider.of(context) inside the widget build function like following (I think you can also try to add it inside the _widgetTask function but I dont know if this would work).
class WidgetTask extends StatelessWidget {
//WidgetTask contructor here..
#override
Widget build(BuildContext context) {
final odooData = Provider.of<OdooData>(context);
And then use the odooData to access the data/functions you need to update/listen to from the provider.
Also you can wrap the widget with GestureDetector so that you can update the widget upon tapping using the OnTap property.
flutterdartdialogrefreshproviderconsumer
I am using the table_calendar package for Flutter.
When I am deleting/updating events to the calendar, I always have to click again on the respective date to see the events afterward.
I want to make this happen automatically. I have not found yet a property to do so.
When adding an event the list gets updated automatically.
I found the solution...
I only had to add the setState(){} method and within it, the deleting of the event would take place. So this is how it looks like:
setState(() { customEvents[_controller.selectedDay].removeAt(index); });
In my case, I used a Stateful Widget as a state management "tool". By wrapping the deletion with setState, I update the state and thus the screen.
I want my app to get an intent, and depending on the intent to display something in the app.
Normally, when a widget depends on state, you put it in a State and run setState().
The issue is that when I try starting my flutter app with different intents, I just get I/FlutterActivityDelegate( 4472): onResume setting current activity to this. And in a way it makes sense - I'm not saying anywhere in the flutter code that my widget needs repainting - since I get my intent through Java.
On the other hand, there should be a way to tell flutter to repaint my widget by intent? Or is there something else I should do?
Specifically to get notified about onResume event you can use WidgetsBindingObserver. Implement its didChangeAppLifecycleState method and respond to AppLifecycleState.resumed by doing whatever it is you want the UI to do, such as call setState to trigger rebuild. That said, there needs to be an effective change for the UI to be repainted. Simply calling setState with no effective state change may not result (in fact, should not) in actual UI changes.
In general, you can send a message from Java (or Objective-C/Swift) to Flutter using BasicMessageChannel and make your app react to the message (e.g. call setState or schedule frames).