-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 Refine comments for clarity and readability
- Loading branch information
Alex
committed
Nov 15, 2024
1 parent
dd5245c
commit 59984b9
Showing
1 changed file
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
import 'package:camelus/config/palette.dart'; | ||
import 'package:camelus/config/palette.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Creates a custom long button widget. | ||
/// | ||
/// This button is highly configurable with options for text, | ||
/// loading state and disabled state. | ||
Widget longButton({ | ||
required String name, | ||
required Function() onPressed, | ||
bool inverted = false, | ||
bool disabled = false, | ||
bool loading = false, | ||
required String name, | ||
required Function() onPressed, // Callback function for button press. | ||
bool inverted = false, // If true, swaps the color scheme for the button. | ||
bool disabled = false, // If true, disables the button. | ||
bool loading = false, // If true, displays a loading indicator instead of text. | ||
}) { | ||
return ElevatedButton( | ||
// Disable the button if `disabled` is true and not in a loading state. | ||
onPressed: disabled && !loading ? null : onPressed, | ||
style: ElevatedButton.styleFrom( | ||
disabledBackgroundColor: Palette.darkGray, | ||
foregroundColor: inverted ? Palette.black : Palette.lightGray, | ||
backgroundColor: inverted ? Palette.extraLightGray : Palette.black, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
side: const BorderSide(color: Palette.white, width: 1), | ||
borderRadius: BorderRadius.circular(20), | ||
side: const BorderSide(color: Palette.white, width: 1), | ||
), | ||
), | ||
// Show a loading indicator if `loading` is true; otherwise, display text. | ||
child: loading | ||
? _progress() | ||
? _progress() // Widget to show a progress indicator. | ||
: Text( | ||
name, | ||
name, // Button text. | ||
style: TextStyle( | ||
color: inverted ? Palette.black : Palette.white, | ||
fontSize: 18, | ||
color: inverted ? Palette.black : Palette.white, // Text color. | ||
fontSize: 18, // Font size for the text. | ||
), | ||
), | ||
); | ||
} | ||
|
||
/// Creates a loading indicator widget for the button. | ||
/// | ||
/// This is a linear progress bar styled with colors defined in the `Palette`. | ||
Widget _progress() { | ||
return const Padding( | ||
padding: EdgeInsets.only(left: 10, right: 10), | ||
padding: EdgeInsets.only(left: 10, right: 10), | ||
child: LinearProgressIndicator( | ||
backgroundColor: Palette.gray, | ||
color: Palette.black, | ||
backgroundColor: Palette.gray, | ||
color: Palette.black, | ||
), | ||
); | ||
} |