Skip to content

Commit 3ed0bbe

Browse files
authored
CupertinoActivityIndicator: Add an interactive example (#103040)
1 parent 86e55df commit 3ed0bbe

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flutter code sample for CupertinoActivityIndicator
6+
7+
import 'package:flutter/cupertino.dart';
8+
9+
void main() => runApp(const CupertinoIndicatorApp());
10+
11+
class CupertinoIndicatorApp extends StatelessWidget {
12+
const CupertinoIndicatorApp({Key? key}) : super(key: key);
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return const CupertinoApp(
17+
theme: CupertinoThemeData(brightness: Brightness.light),
18+
home: CupertinoIndicatorExample(),
19+
);
20+
}
21+
}
22+
23+
class CupertinoIndicatorExample extends StatelessWidget {
24+
const CupertinoIndicatorExample({Key? key}) : super(key: key);
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
29+
return CupertinoPageScaffold(
30+
child: Center(
31+
child: Column(
32+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
33+
children: <Widget>[
34+
Column(
35+
mainAxisAlignment: MainAxisAlignment.center,
36+
children: const <Widget>[
37+
// Cupertino activity indicator with default properties.
38+
CupertinoActivityIndicator(),
39+
SizedBox(height: 10),
40+
Text('Default'),
41+
],
42+
),
43+
Column(
44+
mainAxisAlignment: MainAxisAlignment.center,
45+
children: const <Widget>[
46+
// Cupertino activity indicator with custom radius and color.
47+
CupertinoActivityIndicator(radius: 20.0, color: CupertinoColors.activeBlue),
48+
SizedBox(height: 10),
49+
Text(
50+
'radius: 20.0\ncolor: CupertinoColors.activeBlue',
51+
textAlign: TextAlign.center,
52+
),
53+
],
54+
),
55+
Column(
56+
mainAxisAlignment: MainAxisAlignment.center,
57+
children: const <Widget>[
58+
// Cupertino activity indicator with custom radius and disabled animation.
59+
CupertinoActivityIndicator(radius: 20.0, animating: false),
60+
SizedBox(height: 10),
61+
Text(
62+
'radius: 20.0\nanimating: false',
63+
textAlign: TextAlign.center,
64+
),
65+
],
66+
),
67+
],
68+
),
69+
)
70+
);
71+
}
72+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/cupertino.dart';
6+
import 'package:flutter_api_samples/cupertino/activity_indicator/cupertino_activity_indicator.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Default and customized cupertino activity indicators', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.CupertinoIndicatorApp(),
13+
);
14+
15+
// Cupertino activity indicator with default properties.
16+
final Finder firstIndicator = find.byType(CupertinoActivityIndicator).at(0);
17+
expect(tester.widget<CupertinoActivityIndicator>(firstIndicator).animating, true);
18+
expect(tester.widget<CupertinoActivityIndicator>(firstIndicator).radius, 10.0);
19+
20+
// Cupertino activity indicator with custom radius and color.
21+
final Finder secondIndicator = find.byType(CupertinoActivityIndicator).at(1);
22+
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).animating, true);
23+
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).radius, 20.0);
24+
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).color, CupertinoColors.activeBlue);
25+
26+
// Cupertino activity indicator with custom radius and disabled animation.
27+
final Finder thirdIndicator = find.byType(CupertinoActivityIndicator).at(2);
28+
expect(tester.widget<CupertinoActivityIndicator>(thirdIndicator).animating, false);
29+
expect(tester.widget<CupertinoActivityIndicator>(thirdIndicator).radius, 20.0);
30+
});
31+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const Color _kActiveTickColor = CupertinoDynamicColor.withBrightness(
2020
///
2121
/// {@youtube 560 315 https://www.youtube.com/watch?v=AENVH-ZqKDQ}
2222
///
23+
/// {@tool dartpad}
24+
/// This example shows how [CupertinoActivityIndicator] can be customized.
25+
///
26+
/// ** See code in examples/api/lib/cupertino/activity_indicator/cupertino_activity_indicator.0.dart **
27+
/// {@end-tool}
28+
///
2329
/// See also:
2430
///
2531
/// * <https://developer.apple.com/ios/human-interface-guidelines/controls/progress-indicators/#activity-indicators>

0 commit comments

Comments
 (0)