Flutter Table Calendar Event List Refresh - flutter

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.

Related

updateDisplayName in action without reloading simulator

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.

How can I notify other screen to re-fetch when there is a mutation?

I have some api that are going to change the data in the backend.
Each screen has its own state, I start fetch the data in the initState, and store it to the state once available.
The problem is how can I notify the screen in the backstack to refetch when I know their data in the state is now outdated? They won't be refetch when I am back to them since the initState won't be called again.
I come from React Native, where there is react-query, which will refetch and rebuild the screen when I invalidate the corresponding cache. Is something similar available in flutter?
You can try this, please put this on your first screen.
Navigator.of(context).pushNamed('/someRoute').then((completion){
your initstate function
});
Ref : https://api.flutter.dev/flutter/widgets/Navigator/push.html
If you need to notify more then one screens, use https://pub.dev/packages/flutter_bloc (There are other options) instead.

Flutter - Listening to one value through whole app

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.

How to refresh Dialog when the data has change? Flutter

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

React Native: what lifecycle should I look for when I want to refresh ListView whenever I navigate back to it?

Pretty much like the official tutorial here https://facebook.github.io/react-native/docs/tutorial.html:
I have the fetchData method called in ComponentDidMount, but according to this, ComponentDidMountwould only be called once after initial rendering of the component. So should I do call the same fetchData everytime before I navigate back to this ListView, and pass the updated data as props to the ListView, and then update the listView's state parameter accordingly in componentDidUpdate? Or is there any better way to do this?
You should register an event listener on componentDidMount and unregister it on componentWillUnmout, and emit events whenever and wherever you change the data your component displays.
Good rundown of this pattern here: https://colinramsay.co.uk/2015/07/04/react-native-eventemitters.html