|
1 |
| -import 'package:camelus/config/palette.dart'; |
| 1 | +import 'package:camelus/config/palette.dart'; |
2 | 2 | import 'package:flutter/material.dart';
|
3 | 3 |
|
| 4 | +/// Creates a custom long button widget. |
| 5 | +/// |
| 6 | +/// This button is highly configurable with options for text, |
| 7 | +/// loading state and disabled state. |
4 | 8 | Widget longButton({
|
5 |
| - required String name, |
6 |
| - required Function() onPressed, |
7 |
| - bool inverted = false, |
8 |
| - bool disabled = false, |
9 |
| - bool loading = false, |
| 9 | + required String name, |
| 10 | + required Function() onPressed, // Callback function for button press. |
| 11 | + bool inverted = false, // If true, swaps the color scheme for the button. |
| 12 | + bool disabled = false, // If true, disables the button. |
| 13 | + bool loading = false, // If true, displays a loading indicator instead of text. |
10 | 14 | }) {
|
11 | 15 | return ElevatedButton(
|
| 16 | + // Disable the button if `disabled` is true and not in a loading state. |
12 | 17 | onPressed: disabled && !loading ? null : onPressed,
|
13 | 18 | style: ElevatedButton.styleFrom(
|
14 | 19 | disabledBackgroundColor: Palette.darkGray,
|
15 | 20 | foregroundColor: inverted ? Palette.black : Palette.lightGray,
|
16 | 21 | backgroundColor: inverted ? Palette.extraLightGray : Palette.black,
|
17 | 22 | shape: RoundedRectangleBorder(
|
18 |
| - borderRadius: BorderRadius.circular(20), |
19 |
| - side: const BorderSide(color: Palette.white, width: 1), |
| 23 | + borderRadius: BorderRadius.circular(20), |
| 24 | + side: const BorderSide(color: Palette.white, width: 1), |
20 | 25 | ),
|
21 | 26 | ),
|
| 27 | + // Show a loading indicator if `loading` is true; otherwise, display text. |
22 | 28 | child: loading
|
23 |
| - ? _progress() |
| 29 | + ? _progress() // Widget to show a progress indicator. |
24 | 30 | : Text(
|
25 |
| - name, |
| 31 | + name, // Button text. |
26 | 32 | style: TextStyle(
|
27 |
| - color: inverted ? Palette.black : Palette.white, |
28 |
| - fontSize: 18, |
| 33 | + color: inverted ? Palette.black : Palette.white, // Text color. |
| 34 | + fontSize: 18, // Font size for the text. |
29 | 35 | ),
|
30 | 36 | ),
|
31 | 37 | );
|
32 | 38 | }
|
33 | 39 |
|
| 40 | +/// Creates a loading indicator widget for the button. |
| 41 | +/// |
| 42 | +/// This is a linear progress bar styled with colors defined in the `Palette`. |
34 | 43 | Widget _progress() {
|
35 | 44 | return const Padding(
|
36 |
| - padding: EdgeInsets.only(left: 10, right: 10), |
| 45 | + padding: EdgeInsets.only(left: 10, right: 10), |
37 | 46 | child: LinearProgressIndicator(
|
38 |
| - backgroundColor: Palette.gray, |
39 |
| - color: Palette.black, |
| 47 | + backgroundColor: Palette.gray, |
| 48 | + color: Palette.black, |
40 | 49 | ),
|
41 | 50 | );
|
42 | 51 | }
|
0 commit comments