Open Alijaaan opened 3 years ago
Hi Ali. Thank you for creating issue.
Could you share the onSelectedDateChange part of your code?
Hi Ali. Thank you for creating issue.
Could you share the onSelectedDateChange part of your code?
Hi dear Moradi, many thanks for your reply,
this is how I used date picker :
FlutterDatePickerTimeline( calendarMode: CalendarMode.jalali, startDate: DateTime.now(), endDate: DateTime.now().add(Duration(days: 14)), initialSelectedDate: DateTime.now(), selectedItemBackgroundColor: Colors.purple, itemRadius: 5, onSelectedDateChange: (DateTime dateTime) { setState(() { eventDate = dateTime; }); }, ),
I tested your code that you commented and see no issue and bug. (Also you could test the setState in FlutterDatePickerTimeline example project).
My guess is that the reason for this problem is the parent of FlutterDatePickerTimeline in your code.
According to the error message which you commented in issue, I think the parent of FlutterDatePickerTimeline in your code height is not enough for render or re-render FlutterDatePickerTimeline. If you need smaller FlutterDatePickerTimeline item, instead of using Container with smaller height or width please use below parameters:
selectedItemWidth
unselectedItemWidth
itemHeight
If you can please share more code from your source code to find out the problem.
Dear Moradi, My problem is when I'm doing setState ,it tries to add another list everytime, Even when I removed everything in my page and I used only sample code.
`
This AddNewEventPage widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase. The widget on which setState() or markNeedsBuild() was called was: AddNewEventPage state: _AddNewEventPageState#e3cba The widget which was currently being built when the offending call was made was: Container constraints: BoxConstraints(0.0<=w<=Infinity, h=35.0) The relevant error-causing widget was: Container file:///D:/Alijaan/flutter/event/lib/pages/home/addNewEvent.dart:1178:20 When the exception was thrown, this was the stack:
... `
Maybe it related to my flutter version :
Flutter 2.2.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 02c026b03c (13 days ago) • 2021-05-27 12:24:44 -0700 Engine • revision 0fdb562ac8 Tools • Dart 2.13.1
I found when I'm setting initialSelectedDate I receive this error, but when I'm not setting anything in initialSelectedDate the error will disappear.
Is there any way to solve this problem, or maybe I'm doing something wrong?
I tested both case and see no error and issue.
If you can please share more code from your source code here or send me in private via email to find out the problem.
im having the same issue, i cant setState
in onSelectedDateChange
the error says setState() or markNeedsBuild() called during build.
To get around the issue i used a Timer
in the onSelectedDateChange
like this :
Timer(Duration(milliseconds: 500), (){ setState(() { });});
You could use ValueNotifier as the following example, it works with me. https://medium.com/swlh/use-valuenotifier-like-pro-6441d9ddad05
late ValueNotifier<DateTime> timelineDate;
@override
void initState() {
super.initState();
timelineDate = ValueNotifier<DateTime>(DateTime.now());
}
@override
void dispose() {
timelineDate.dispose();
super.dispose();
}
FlutterDatePickerTimeline(
...,
...,
initialSelectedDate: DateTime.now(),
onSelectedDateChange: (date) {
timelineDate.value = date!;
},
),
// and wrap the widget with the
ValueListenableBuilder(
valueListenable: timelineDate,
builder: (context, value, child) {
return Text(timelineDate.value.toString());
}
);
hope this would work.
I had the same problem. You will get this error if you type initialSelectedDate as follows
initialFocusedDate: DateTime.now(),
To avoid this error, set the initialSelectedDate as follows
initialSelectedDate: DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day),
Hi friend, Thanks for your nice package, but I have a problem, When I'm doing setState in onSelectedDateChange I have the error :