LinearProgressIndicator widget and Attributes

LinearProgressIndicator widget and Attributes

ยท

1 min read

The LinearProgressIndicator widget in Flutter is a linear progress indicator commonly used to display the progress of a task. It provides a visual representation of the completion status of an ongoing process.

Attributes:

  1. value (double):

    • The current progress value of the indicator. If null, the indicator will appear in an indeterminate (continuous animation) state.
  2. backgroundColor (Color):

    • The background color of the indicator.
  3. valueColor (Animation<Color>):

    • The color of the indicator's value. It can be animated, allowing for smooth transitions between colors.

Example:

import 'package:flutter/material.dart';

class LinearProgressIndicatorExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('LinearProgressIndicator Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Uploading...'),
            SizedBox(height: 16),
            LinearProgressIndicator(), // Default LinearProgressIndicator
            SizedBox(height: 16),
            LinearProgressIndicator(
              value: 0.5, // Show progress at 50%
              backgroundColor: Colors.grey,
              valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
            ),
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(
    MaterialApp(
      home: LinearProgressIndicatorExample(),
    ),
  );
}

In this example, there are two LinearProgressIndicator widgets. The first one is the default indicator that shows continuous animation, indicating ongoing progress. The second one is customized with a progress value of 50%, a grey background, and a blue value color. This illustrates how you can use the LinearProgressIndicator to provide visual feedback on the completion status of tasks in your Flutter app.

ย