Skip to content

Commit e8ede58

Browse files
committed
Merge remote-tracking branch 'source-origin/master' into decoupling-progress-indicator
Merging in progress indicator examples from flutter/flutter.
2 parents 2060cd3 + b41318d commit e8ede58

5 files changed

Lines changed: 529 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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/material.dart';
6+
7+
/// Flutter code sample for [CircularProgressIndicator].
8+
9+
void main() => runApp(const ProgressIndicatorExampleApp());
10+
11+
class ProgressIndicatorExampleApp extends StatelessWidget {
12+
const ProgressIndicatorExampleApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return const MaterialApp(home: ProgressIndicatorExample());
17+
}
18+
}
19+
20+
class ProgressIndicatorExample extends StatefulWidget {
21+
const ProgressIndicatorExample({super.key});
22+
23+
@override
24+
State<ProgressIndicatorExample> createState() =>
25+
_ProgressIndicatorExampleState();
26+
}
27+
28+
class _ProgressIndicatorExampleState extends State<ProgressIndicatorExample>
29+
with TickerProviderStateMixin {
30+
late AnimationController controller;
31+
bool year2023 = true;
32+
33+
@override
34+
void initState() {
35+
super.initState();
36+
controller =
37+
AnimationController(vsync: this, duration: const Duration(seconds: 5))
38+
..addListener(() {
39+
setState(() {});
40+
})
41+
..repeat(reverse: true);
42+
}
43+
44+
@override
45+
void dispose() {
46+
controller.dispose();
47+
super.dispose();
48+
}
49+
50+
@override
51+
Widget build(BuildContext context) {
52+
return Scaffold(
53+
body: Center(
54+
child: Column(
55+
spacing: 16.0,
56+
mainAxisAlignment: .center,
57+
children: <Widget>[
58+
const Text('Determinate CircularProgressIndicator'),
59+
Padding(
60+
padding: const .symmetric(horizontal: 16),
61+
child: CircularProgressIndicator(
62+
// ignore: deprecated_member_use
63+
year2023: year2023,
64+
value: controller.value,
65+
),
66+
),
67+
const Text('Indeterminate CircularProgressIndicator'),
68+
Padding(
69+
padding: const .symmetric(horizontal: 16),
70+
// ignore: deprecated_member_use
71+
child: CircularProgressIndicator(year2023: year2023),
72+
),
73+
SwitchListTile(
74+
value: year2023,
75+
title: year2023
76+
? const Text('Switch to latest M3 style')
77+
: const Text('Switch to year2023 M3 style'),
78+
onChanged: (bool value) {
79+
setState(() {
80+
year2023 = !year2023;
81+
});
82+
},
83+
),
84+
],
85+
),
86+
),
87+
);
88+
}
89+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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/material.dart';
6+
7+
/// Flutter code sample for [CircularProgressIndicator].
8+
9+
void main() => runApp(const ProgressIndicatorExampleApp());
10+
11+
class ProgressIndicatorExampleApp extends StatelessWidget {
12+
const ProgressIndicatorExampleApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4)),
18+
home: const ProgressIndicatorExample(),
19+
);
20+
}
21+
}
22+
23+
class ProgressIndicatorExample extends StatefulWidget {
24+
const ProgressIndicatorExample({super.key});
25+
26+
@override
27+
State<ProgressIndicatorExample> createState() =>
28+
_ProgressIndicatorExampleState();
29+
}
30+
31+
class _ProgressIndicatorExampleState extends State<ProgressIndicatorExample>
32+
with TickerProviderStateMixin {
33+
late AnimationController controller;
34+
bool determinate = false;
35+
36+
@override
37+
void initState() {
38+
controller =
39+
AnimationController(
40+
/// [AnimationController]s can be created with `vsync: this` because of
41+
/// [TickerProviderStateMixin].
42+
vsync: this,
43+
duration: const Duration(seconds: 2),
44+
)..addListener(() {
45+
setState(() {});
46+
});
47+
controller.repeat(reverse: true);
48+
super.initState();
49+
}
50+
51+
@override
52+
void dispose() {
53+
controller.dispose();
54+
super.dispose();
55+
}
56+
57+
@override
58+
Widget build(BuildContext context) {
59+
return Scaffold(
60+
body: Padding(
61+
padding: const .all(20.0),
62+
child: Column(
63+
spacing: 16.0,
64+
mainAxisAlignment: .center,
65+
children: <Widget>[
66+
Text(
67+
'Circular progress indicator',
68+
style: Theme.of(context).textTheme.titleLarge,
69+
),
70+
CircularProgressIndicator(
71+
value: controller.value,
72+
semanticsLabel: 'Circular progress indicator',
73+
),
74+
Row(
75+
children: <Widget>[
76+
Expanded(
77+
child: Text(
78+
'determinate Mode',
79+
style: Theme.of(context).textTheme.titleSmall,
80+
),
81+
),
82+
Switch(
83+
value: determinate,
84+
onChanged: (bool value) {
85+
setState(() {
86+
determinate = value;
87+
if (determinate) {
88+
controller.stop();
89+
} else {
90+
controller
91+
..forward(from: controller.value)
92+
..repeat();
93+
}
94+
});
95+
},
96+
),
97+
],
98+
),
99+
],
100+
),
101+
),
102+
);
103+
}
104+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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/material.dart';
6+
7+
/// Flutter code sample for [CircularProgressIndicator].
8+
9+
void main() => runApp(const ProgressIndicatorExampleApp());
10+
11+
class ProgressIndicatorExampleApp extends StatelessWidget {
12+
const ProgressIndicatorExampleApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4)),
18+
home: const ProgressIndicatorExample(),
19+
);
20+
}
21+
}
22+
23+
class ProgressIndicatorExample extends StatefulWidget {
24+
const ProgressIndicatorExample({super.key});
25+
26+
@override
27+
State<ProgressIndicatorExample> createState() =>
28+
_ProgressIndicatorExampleState();
29+
}
30+
31+
class _ProgressIndicatorExampleState extends State<ProgressIndicatorExample>
32+
with TickerProviderStateMixin {
33+
late AnimationController controller;
34+
int indicatorNum = 1;
35+
bool hasThemeController = true;
36+
37+
@override
38+
void initState() {
39+
controller = AnimationController(
40+
vsync: this,
41+
duration: CircularProgressIndicator.defaultAnimationDuration * 0.8,
42+
);
43+
controller.repeat();
44+
super.initState();
45+
}
46+
47+
@override
48+
void dispose() {
49+
controller.dispose();
50+
super.dispose();
51+
}
52+
53+
@override
54+
Widget build(BuildContext context) {
55+
return Scaffold(
56+
body: Theme(
57+
data: ThemeData(
58+
progressIndicatorTheme: hasThemeController
59+
? ProgressIndicatorThemeData(controller: controller)
60+
: null,
61+
),
62+
child: Padding(
63+
padding: const .all(20.0),
64+
child: Column(
65+
spacing: 8.0,
66+
children: <Widget>[
67+
Row(
68+
mainAxisAlignment: .center,
69+
children: <Widget>[
70+
TextButton(
71+
onPressed: () {
72+
setState(() {
73+
indicatorNum += 1;
74+
});
75+
},
76+
child: const Text('More indicators'),
77+
),
78+
TextButton(
79+
onPressed: () {
80+
setState(() {
81+
indicatorNum -= 1;
82+
});
83+
},
84+
child: const Text('Fewer indicators'),
85+
),
86+
],
87+
),
88+
Row(
89+
mainAxisAlignment: .center,
90+
children: <Widget>[
91+
Text(
92+
'Theme controller? ${hasThemeController ? 'Yes' : 'No'}',
93+
),
94+
TextButton(
95+
onPressed: () {
96+
setState(() {
97+
hasThemeController = !hasThemeController;
98+
});
99+
},
100+
child: const Text('Toggle'),
101+
),
102+
],
103+
),
104+
ManyProgressIndicators(indicatorNum: indicatorNum),
105+
],
106+
),
107+
),
108+
),
109+
);
110+
}
111+
}
112+
113+
/// Display several [CircularProgressIndicator] in nested `Container`s.
114+
class ManyProgressIndicators extends StatelessWidget {
115+
const ManyProgressIndicators({super.key, required this.indicatorNum});
116+
117+
final int indicatorNum;
118+
119+
Widget _nestIndicator({required Widget child}) {
120+
return Container(
121+
padding: const .all(5),
122+
margin: const .all(5),
123+
decoration: BoxDecoration(
124+
color: const Color.fromARGB(100, 240, 240, 0),
125+
border: .all(),
126+
),
127+
child: Column(
128+
mainAxisAlignment: .center,
129+
children: <Widget>[const CircularProgressIndicator(), child],
130+
),
131+
);
132+
}
133+
134+
@override
135+
Widget build(BuildContext context) {
136+
Widget child = const SizedBox();
137+
for (int i = 0; i < indicatorNum; i++) {
138+
child = _nestIndicator(child: child);
139+
}
140+
return child;
141+
}
142+
}

0 commit comments

Comments
 (0)