Flutter CupertinoActivityIndicator Progress
To set a specific progress to CupertinoActivityIndicator widget in Flutter, create CupertinoActivityIndicator widget using CupertinoActivityIndicator.partiallyRevealed() constructor and pass the progress as argument.
Syntax
A CupertinoActivityIndicator with specific radius.
CupertinoActivityIndicator(
radius: 20,
),
Example
Flutter Application with a CupertinoActivityIndicator widget.
We declared a variable activityProgress
with an initial value of 0.4 (40%), and assign it to progress
property of CupertinoActivityIndicator widget.
main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// main application widget
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Application';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
);
}
}
/// stateful widget that the main application instantiates
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// private State class that goes with MyStatefulWidget
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
double activityProgress = 0.4;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
const SizedBox(height: 30,),
CupertinoActivityIndicator.partiallyRevealed(
radius: 40,
progress: activityProgress,
),
],
),
);
}
}
Screenshot
Now, let us include a button, in our application that increases the progress by 10% for each click, and resets to 10% after 100%.
main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// main application widget
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Application';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
);
}
}
/// stateful widget that the main application instantiates
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// private State class that goes with MyStatefulWidget
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
double activityProgress = 0.4;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
const SizedBox(height: 30,),
CupertinoActivityIndicator.partiallyRevealed(
radius: 40,
progress: activityProgress,
),
CupertinoButton(
child: const Text('Change Progress'),
onPressed: () {
setState(() {
if (activityProgress < 0.9) {
activityProgress = activityProgress + 0.1;
} else {
activityProgress = 0.1;
}
});
}
),
],
),
);
}
}
Video