I have a text widget in the cellBuilder of SF Datepicker in my app whose color should conditionally render on the basis of a state of a variable. When I change the state, the widget is getting re-rendered(the latest value of the state of the variable is printed and another text widget outside of cellBuilder which conditionally renders on the basis of the state also works fine). But the color of the text doesn't change. This is the build method of the main widget:
@override
Widget build(BuildContext context) {
return Column(
children: [
unfinishedWeeks.length > 0
? Text("Unfinished weeks")
: Container(), //This text is visible when the state of unfinishedWeeks changes
Container(
height: 320,
child: SfDateRangePicker(
controller: _controller,
cellBuilder:
(BuildContext context, DateRangePickerCellDetails details) {
debugPrint(unfinishedWeeks
.toString()); //the current state of unfinishedWeeks is printed
return Text(
details.date.day.toString(),
style: TextStyle(
color: unfinishedWeeks.length >
0 //this value doesn't change when the state of unfinishedWeeks changes
? Color.fromARGB(255, 170, 0, 0)
: Color.fromARGB(255, 47, 15, 83),
),
);
},
),
),
],
);
}
Where am I going wrong? Does it have to do with SF Datepicker?
CodePudding user response:
SfDateRangePicker rebuild UI only when the onSelectionChanged function is called
CodePudding user response:
Can you try calling setState
on the section where unfinishedWeeks
is being updated.
CodePudding user response:
I figured out a way: using Keys to force the UI to re-render. So I created a new widget enclosing the text widget and provided this widget with a key.