From 59984b96c4ddea127bc428a2cc8a9534ff7359b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 15 Nov 2024 15:45:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Refine=20comments=20for=20clarit?= =?UTF-8?q?y=20and=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/presentation_layer/atoms/long_button.dart | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/presentation_layer/atoms/long_button.dart b/lib/presentation_layer/atoms/long_button.dart index 79644142..0be68850 100644 --- a/lib/presentation_layer/atoms/long_button.dart +++ b/lib/presentation_layer/atoms/long_button.dart @@ -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, ), ); }