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> { ...@@ -1990,6 +1990,10 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
late double totalWidth; late double totalWidth;
late double pickerColumnWidth; late double pickerColumnWidth;
FixedExtentScrollController? _hourScrollController;
FixedExtentScrollController? _minuteScrollController;
FixedExtentScrollController? _secondScrollController;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -2019,6 +2023,10 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> { ...@@ -2019,6 +2023,10 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
void dispose() { void dispose() {
PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange); PaintingBinding.instance.systemFonts.removeListener(_handleSystemFontsChange);
textPainter.dispose(); textPainter.dispose();
_hourScrollController?.dispose();
_minuteScrollController?.dispose();
_secondScrollController?.dispose();
super.dispose(); super.dispose();
} }
...@@ -2164,8 +2172,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> { ...@@ -2164,8 +2172,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
} }
Widget _buildHourPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { Widget _buildHourPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
_hourScrollController ??= FixedExtentScrollController(
initialItem: selectedHour!
);
return CupertinoPicker( return CupertinoPicker(
scrollController: FixedExtentScrollController(initialItem: selectedHour!), scrollController: _hourScrollController,
magnification: _kMagnification, magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction(additionalPadding.start, 0), offAxisFraction: _calculateOffAxisFraction(additionalPadding.start, 0),
itemExtent: widget.itemExtent, itemExtent: widget.itemExtent,
...@@ -2223,10 +2234,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> { ...@@ -2223,10 +2234,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
} }
Widget _buildMinutePicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { Widget _buildMinutePicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
return CupertinoPicker( _minuteScrollController ??= FixedExtentScrollController(
scrollController: FixedExtentScrollController(
initialItem: selectedMinute ~/ widget.minuteInterval, initialItem: selectedMinute ~/ widget.minuteInterval,
), );
return CupertinoPicker(
scrollController: _minuteScrollController,
magnification: _kMagnification, magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction( offAxisFraction: _calculateOffAxisFraction(
additionalPadding.start, additionalPadding.start,
...@@ -2289,10 +2301,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> { ...@@ -2289,10 +2301,11 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
} }
Widget _buildSecondPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) { Widget _buildSecondPicker(EdgeInsetsDirectional additionalPadding, Widget selectionOverlay) {
return CupertinoPicker( _secondScrollController ??= FixedExtentScrollController(
scrollController: FixedExtentScrollController(
initialItem: selectedSecond! ~/ widget.secondInterval, initialItem: selectedSecond! ~/ widget.secondInterval,
), );
return CupertinoPicker(
scrollController: _secondScrollController,
magnification: _kMagnification, magnification: _kMagnification,
offAxisFraction: _calculateOffAxisFraction( offAxisFraction: _calculateOffAxisFraction(
additionalPadding.start, additionalPadding.start,
......
...@@ -218,6 +218,7 @@ class _CupertinoPickerState extends State<CupertinoPicker> { ...@@ -218,6 +218,7 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
void didUpdateWidget(CupertinoPicker oldWidget) { void didUpdateWidget(CupertinoPicker oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (widget.scrollController != null && oldWidget.scrollController == null) { if (widget.scrollController != null && oldWidget.scrollController == null) {
_controller?.dispose();
_controller = null; _controller = null;
} else if (widget.scrollController == null && oldWidget.scrollController != null) { } else if (widget.scrollController == null && oldWidget.scrollController != null) {
assert(_controller == 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