Below is a Flutter widget that implements the UI you described, including a title with an amount, a progress bar, and step information. I've structured it as a reusable widget for better organization and readability.
import 'package:flutter/material.dart';
class ProgressStepWidget extends StatelessWidget {
final String amount;
final int currentStep;
final int totalSteps;
final String nextStepText;
const ProgressStepWidget({
Key? key,
required this.amount,
required this.currentStep,
required this.totalSteps,
required this.nextStepText,
}) : super(key: key);
@override
Widget build(BuildContext context) {
// Calculate progress value for the LinearProgressIndicator
double progressValue = currentStep / totalSteps;
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Title and amount
Text(
amount,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
// Progress bar
Text(
"Шаг $currentStep из $totalSteps",
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 10),
LinearProgressIndicator(
value: progressValue, // Adjust based on step
backgroundColor: Colors.grey[300],
color: Colors.red,
minHeight: 8, // Optional: Adjust the height of the progress bar
),
const SizedBox(height: 10),
// Next step text
Text(
nextStepText,
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
],
);
}
}
// Example usage in your app
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("Progress Step Example")),
body: const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: ProgressStepWidget(
amount: "15 000 ₽",
currentStep: 1,
totalSteps: 3,
nextStepText: "Следующий шаг: данные паспорта РФ",
),
),
),
),
);
}
}
Explanation of the Code:
-
Custom Widget (ProgressStepWidget):
- This is a reusable widget that takes parameters like
amount, currentStep, totalSteps, and nextStepText to make it dynamic and reusable.
- The
progressValue is calculated as currentStep / totalSteps to determine the progress bar's fill level.
-
UI Components:
- Amount Text: Displays the amount (e.g., "15 000 ₽") in a bold, large font.
- Step Text: Shows the current step out of the total steps (e.g., "Шаг 1 из 3").
- LinearProgressIndicator: A progress bar that visually represents the current step. The
value is a double between 0.0 and 1.0, where 0.33 means 33% completion.
- Next Step Text: Displays the next step information in a smaller, grey font.
-
Styling:
- The
TextStyle is used to customize font sizes, weights, and colors.
- The
LinearProgressIndicator uses Colors.grey[300] for the background and Colors.red for the progress color, matching your description.
SizedBox widgets are used to add spacing between elements for better layout.
-
Example Usage:
- The
main function demonstrates how to use the ProgressStepWidget in a simple Flutter app. You can integrate this widget into any part of your app by passing the required parameters.
Customization:
- You can adjust the
fontSize, color, or other properties to match your app's design.
- If you want to add animations to the progress bar, you can wrap the
LinearProgressIndicator in an AnimatedContainer or use TweenAnimationBuilder.
Output:
When you run the code, it will display a centered column with:
- The amount "15 000 ₽" in bold.
- The step text "Шаг 1 из 3".
- A progress bar filled to 33% (since it's step 1 out of 3).
- The next step text "Следующий шаг: данные паспорта РФ".
Let me know if you need further assistance or additional features!