Unverified Commit 7646430c authored by derdilla's avatar derdilla Committed by GitHub

Cupertino date picker should dispose scroll controllers it created. (#135355)

parent 24adfe1c
......@@ -1990,6 +1990,10 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
late double totalWidth;
late double pickerColumnWidth;
FixedExtentScrollController? _hourScrollController;
FixedExtentScrollController? _minuteScrollController;
FixedExtentScrollController? _secondScrollController;
@override
void initState() {
super.initState();
......@@ -2019,6 +2023,10 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
void dispose() {
PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange);
textPainter.dispose();
_hourScrollController?.dispose();
_minuteScrollController?.dispose();
_secondScrollController?.dispose();
super.dispose();
}
......@@ -2164,8 +2172,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
}
Widget _buildHourPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
_hourScrollController ??= FixedExtentScrollController(
initialItem: selectedHour!
);
return CupertinoPicker(
scrollController: FixedExtentScrollController(initialItem: selectedHour!),
scrollController: _hourScrollController,
magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction(additionalPadding.start, 0),
itemExtent: widget.itemExtent,
......@@ -2223,10 +2234,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
}
Widget _buildMinutePicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
return CupertinoPicker(
scrollController: FixedExtentScrollController(
_minuteScrollController ??= FixedExtentScrollController(
initialItem: selectedMinute ~/ widget.minuteInterval,
),
);
return CupertinoPicker(
scrollController: _minuteScrollController,
magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction(
additionalPadding.start,
......@@ -2289,10 +2301,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
}
Widget _buildSecondPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
return CupertinoPicker(
scrollController: FixedExtentScrollController(
_secondScrollController ??= FixedExtentScrollController(
initialItem: selectedSecond! ~/ widget.secondInterval,
),
);
return CupertinoPicker(
scrollController: _secondScrollController,
magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction(
additionalPadding.start,
......
......@@ -218,6 +218,7 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
void didUpdateWidget(CupertinoPicker oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.scrollController != null && oldWidget.scrollController == null) {
_controller?.dispose();
_controller = null;
} else if (widget.scrollController == null && oldWidget.scrollController != null) {
assert(_controller == null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment