@@ -188,7 +188,7 @@ bool _isInAccessibilityMode(BuildContext context) {
188
188
/// * [CupertinoDialogAction] , which is an iOS-style dialog button.
189
189
/// * [AlertDialog] , a Material Design alert dialog.
190
190
/// * <https://developer.apple.com/ios/human-interface-guidelines/views/alerts/>
191
- class CupertinoAlertDialog extends StatelessWidget {
191
+ class CupertinoAlertDialog extends StatefulWidget {
192
192
/// Creates an iOS-style alert dialog.
193
193
///
194
194
/// The [actions] must not be null.
@@ -233,9 +233,6 @@ class CupertinoAlertDialog extends StatelessWidget {
233
233
/// section when there are many actions.
234
234
final ScrollController ? scrollController;
235
235
236
- ScrollController get _effectiveScrollController =>
237
- scrollController ?? ScrollController ();
238
-
239
236
/// A scroll controller that can be used to control the scrolling of the
240
237
/// actions in the dialog.
241
238
///
@@ -247,37 +244,49 @@ class CupertinoAlertDialog extends StatelessWidget {
247
244
/// section when it is long.
248
245
final ScrollController ? actionScrollController;
249
246
250
- ScrollController get _effectiveActionScrollController =>
251
- actionScrollController ?? ScrollController ();
252
-
253
247
/// {@macro flutter.material.dialog.insetAnimationDuration}
254
248
final Duration insetAnimationDuration;
255
249
256
250
/// {@macro flutter.material.dialog.insetAnimationCurve}
257
251
final Curve insetAnimationCurve;
258
252
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
+
259
268
Widget _buildContent (BuildContext context) {
260
269
final double textScaleFactor = MediaQuery .textScalerOf (context).textScaleFactor;
261
270
262
271
final List <Widget > children = < Widget > [
263
- if (title != null || content != null )
272
+ if (widget. title != null || widget. content != null )
264
273
Flexible (
265
274
flex: 3 ,
266
275
child: _CupertinoAlertContentSection (
267
- title: title,
268
- message: content,
276
+ title: widget. title,
277
+ message: widget. content,
269
278
scrollController: _effectiveScrollController,
270
279
titlePadding: EdgeInsets .only (
271
280
left: _kDialogEdgePadding,
272
281
right: _kDialogEdgePadding,
273
- bottom: content == null ? _kDialogEdgePadding : 1.0 ,
282
+ bottom: widget. content == null ? _kDialogEdgePadding : 1.0 ,
274
283
top: _kDialogEdgePadding * textScaleFactor,
275
284
),
276
285
messagePadding: EdgeInsets .only (
277
286
left: _kDialogEdgePadding,
278
287
right: _kDialogEdgePadding,
279
288
bottom: _kDialogEdgePadding * textScaleFactor,
280
- top: title == null ? _kDialogEdgePadding : 1.0 ,
289
+ top: widget. title == null ? _kDialogEdgePadding : 1.0 ,
281
290
),
282
291
titleTextStyle: _kCupertinoDialogTitleStyle.copyWith (
283
292
color: CupertinoDynamicColor .resolve (CupertinoColors .label, context),
@@ -303,10 +312,10 @@ class CupertinoAlertDialog extends StatelessWidget {
303
312
Widget actionSection = Container (
304
313
height: 0.0 ,
305
314
);
306
- if (actions.isNotEmpty) {
315
+ if (widget. actions.isNotEmpty) {
307
316
actionSection = _CupertinoAlertActionSection (
308
317
scrollController: _effectiveActionScrollController,
309
- children: actions,
318
+ children: widget. actions,
310
319
);
311
320
}
312
321
@@ -330,8 +339,8 @@ class CupertinoAlertDialog extends StatelessWidget {
330
339
return AnimatedPadding (
331
340
padding: MediaQuery .viewInsetsOf (context) +
332
341
const EdgeInsets .symmetric (horizontal: 40.0 , vertical: 24.0 ),
333
- duration: insetAnimationDuration,
334
- curve: insetAnimationCurve,
342
+ duration: widget. insetAnimationDuration,
343
+ curve: widget. insetAnimationCurve,
335
344
child: MediaQuery .removeViewInsets (
336
345
removeLeft: true ,
337
346
removeTop: true ,
@@ -368,6 +377,13 @@ class CupertinoAlertDialog extends StatelessWidget {
368
377
),
369
378
);
370
379
}
380
+
381
+ @override
382
+ void dispose () {
383
+ _backupScrollController? .dispose ();
384
+ _backupActionScrollController? .dispose ();
385
+ super .dispose ();
386
+ }
371
387
}
372
388
373
389
/// Rounded rectangle surface that looks like an iOS popup surface, e.g., alert dialog
0 commit comments