Flutter – Cupertino Activity Indicator
Last Updated :
06 Nov, 2023
The CupertinoActivityIndicator widget in Flutter is a part of the Cupertino widget set, which is designed to provide an iOS-like look and feel to your Flutter apps. It displays an iOS-style circular loading spinner, often used to indicate that some operation is in progress. In this article, we are going to implement the CupertinoActivityIndicator widget. A sample video is given below to get an idea about what we are going to do in this article.
Basic Syntax of CupertinoActivityIndicator Widget
CupertinoActivityIndicator(
radius: 20.0, // Customize the size
animating: true, // Control animation
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue), // Customize color
)
Required Tools
To build this app, you need the following items installed on your machine:
- Visual Studio Code / Android Studio
- Android Emulator / iOS Simulator / Physical Device device.
- Flutter Installed
- Flutter plugin for VS Code / Android Studio.
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Import the Package
First of all import material.dart file.
import 'package:flutter/cupertino.dart';
Step 3: Execute the main Method
Here the execution of our app starts.
Dart
void main() {
runApp(MyApp());
}
|
Step 4: Create CupertinoActivityIndicatorExample Class
In this class we are going to implement the CupertinoApp, here we can also set the Theme of our App. Here we call CupertinoActivityIndicatorExample class where the CupertinoActivityIndicator Widget is implemented .
Dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoApp(
debugShowCheckedModeBanner: false ,
home: CupertinoActivityIndicatorExample(),
);
}
}
|
Step 5: Create CupertinoActivityIndicatorExample Class
In this class we are going to Implement the CupertinoActivityIndicator widget that help to displays an iOS-style circular loading spinner used to indicate that some operation is in progress. Comments are added for better understanding.
Dart
class CupertinoActivityIndicatorExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text( 'Cupertino Activity Indicator Example' ),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CupertinoActivityIndicator(),
SizedBox(
height: 16.0),
Text( 'Loading...' ),
],
),
),
);
}
}
|
Here is the full Code of main.dart file
Dart
import 'package:flutter/cupertino.dart' ;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoApp(
debugShowCheckedModeBanner: false ,
home: CupertinoActivityIndicatorExample(),
);
}
}
class CupertinoActivityIndicatorExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text( 'Cupertino Activity Indicator Example' ),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CupertinoActivityIndicator(),
SizedBox(
height: 16.0),
Text( 'Loading...' ),
],
),
),
);
}
}
|
Output:
Share your thoughts in the comments
Please Login to comment...