Skip to content

Commit a425e56

Browse files
authored
Revert "CupertinoAlertDialog should not create ScrollController on every build, if null values are passed in constructor." (#134071)
Reverts flutter/flutter#133918 as it causes build failures.
1 parent e30f9c4 commit a425e56

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

packages/flutter/lib/src/cupertino/dialog.dart

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool _isInAccessibilityMode(BuildContext context) {
188188
/// * [CupertinoDialogAction], which is an iOS-style dialog button.
189189
/// * [AlertDialog], a Material Design alert dialog.
190190
/// * <https://developer.apple.com/ios/human-interface-guidelines/views/alerts/>
191-
class CupertinoAlertDialog extends StatefulWidget {
191+
class CupertinoAlertDialog extends StatelessWidget {
192192
/// Creates an iOS-style alert dialog.
193193
///
194194
/// The [actions] must not be null.
@@ -233,6 +233,9 @@ class CupertinoAlertDialog extends StatefulWidget {
233233
/// section when there are many actions.
234234
final ScrollController? scrollController;
235235

236+
ScrollController get _effectiveScrollController =>
237+
scrollController ?? ScrollController();
238+
236239
/// A scroll controller that can be used to control the scrolling of the
237240
/// actions in the dialog.
238241
///
@@ -244,49 +247,37 @@ class CupertinoAlertDialog extends StatefulWidget {
244247
/// section when it is long.
245248
final ScrollController? actionScrollController;
246249

250+
ScrollController get _effectiveActionScrollController =>
251+
actionScrollController ?? ScrollController();
252+
247253
/// {@macro flutter.material.dialog.insetAnimationDuration}
248254
final Duration insetAnimationDuration;
249255

250256
/// {@macro flutter.material.dialog.insetAnimationCurve}
251257
final Curve insetAnimationCurve;
252258

253-
@override
254-
State<CupertinoAlertDialog> createState() => _CupertinoAlertDialogState();
255-
}
256-
257-
class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
258-
ScrollController? _backupScrollController;
259-
260-
ScrollController? _backupActionScrollController;
261-
262-
ScrollController get _effectiveScrollController =>
263-
widget.scrollController ?? (_backupScrollController ??= ScrollController());
264-
265-
ScrollController get _effectiveActionScrollController =>
266-
widget.actionScrollController ?? (_backupActionScrollController ??= ScrollController());
267-
268259
Widget _buildContent(BuildContext context) {
269260
final double textScaleFactor = MediaQuery.textScalerOf(context).textScaleFactor;
270261

271262
final List<Widget> children = <Widget>[
272-
if (widget.title != null || widget.content != null)
263+
if (title != null || content != null)
273264
Flexible(
274265
flex: 3,
275266
child: _CupertinoAlertContentSection(
276-
title: widget.title,
277-
message: widget.content,
267+
title: title,
268+
message: content,
278269
scrollController: _effectiveScrollController,
279270
titlePadding: EdgeInsets.only(
280271
left: _kDialogEdgePadding,
281272
right: _kDialogEdgePadding,
282-
bottom: widget.content == null ? _kDialogEdgePadding : 1.0,
273+
bottom: content == null ? _kDialogEdgePadding : 1.0,
283274
top: _kDialogEdgePadding * textScaleFactor,
284275
),
285276
messagePadding: EdgeInsets.only(
286277
left: _kDialogEdgePadding,
287278
right: _kDialogEdgePadding,
288279
bottom: _kDialogEdgePadding * textScaleFactor,
289-
top: widget.title == null ? _kDialogEdgePadding : 1.0,
280+
top: title == null ? _kDialogEdgePadding : 1.0,
290281
),
291282
titleTextStyle: _kCupertinoDialogTitleStyle.copyWith(
292283
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context),
@@ -312,10 +303,10 @@ class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
312303
Widget actionSection = Container(
313304
height: 0.0,
314305
);
315-
if (widget.actions.isNotEmpty) {
306+
if (actions.isNotEmpty) {
316307
actionSection = _CupertinoAlertActionSection(
317308
scrollController: _effectiveActionScrollController,
318-
children: widget.actions,
309+
children: actions,
319310
);
320311
}
321312

@@ -339,8 +330,8 @@ class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
339330
return AnimatedPadding(
340331
padding: MediaQuery.viewInsetsOf(context) +
341332
const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
342-
duration: widget.insetAnimationDuration,
343-
curve: widget.insetAnimationCurve,
333+
duration: insetAnimationDuration,
334+
curve: insetAnimationCurve,
344335
child: MediaQuery.removeViewInsets(
345336
removeLeft: true,
346337
removeTop: true,
@@ -377,13 +368,6 @@ class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
377368
),
378369
);
379370
}
380-
381-
@override
382-
void dispose() {
383-
_backupScrollController?.dispose();
384-
_backupActionScrollController?.dispose();
385-
super.dispose();
386-
}
387371
}
388372

389373
/// Rounded rectangle surface that looks like an iOS popup surface, e.g., alert dialog

packages/flutter/test/material/dialog_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ void main() {
26642664
okNode.dispose();
26652665
});
26662666

2667-
testWidgetsWithLeakTracking('Adaptive AlertDialog shows correct widget on each platform', (WidgetTester tester) async {
2667+
testWidgets('Adaptive AlertDialog shows correct widget on each platform', (WidgetTester tester) async {
26682668
final AlertDialog dialog = AlertDialog.adaptive(
26692669
content: Container(
26702670
height: 5000.0,

0 commit comments

Comments
 (0)