From d2f0e5f1e891f5a708e97ddf60056fd6444a3b7f Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 15 Nov 2024 15:49:20 +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 --- .../atoms/refresh_indicator_no_need.dart | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/presentation_layer/atoms/refresh_indicator_no_need.dart b/lib/presentation_layer/atoms/refresh_indicator_no_need.dart index f937811a..b26bf0fc 100644 --- a/lib/presentation_layer/atoms/refresh_indicator_no_need.dart +++ b/lib/presentation_layer/atoms/refresh_indicator_no_need.dart @@ -1,20 +1,24 @@ -import 'package:camelus/config/palette.dart'; +import 'package:camelus/config/palette.dart'; import 'package:custom_refresh_indicator/custom_refresh_indicator.dart'; import 'package:flutter/material.dart'; +/// A custom refresh indicator widget that displays a message instead of the usual indicator +/// +/// This widget wraps around a child widget and displays a custom indicator with a "no need" message. class RefreshIndicatorNoNeed extends StatelessWidget { final Widget child; - final Future Function() onRefresh; + final Future Function() onRefresh; // The callback function to trigger the refresh. const RefreshIndicatorNoNeed({ Key? key, required this.child, - required this.onRefresh, + required this.onRefresh, // Function that handles the refresh logic. }) : super(key: key); @override Widget build(BuildContext context) { return CustomRefreshIndicator( + // Custom builder for the refresh indicator. builder: ( BuildContext context, Widget child, @@ -23,9 +27,11 @@ class RefreshIndicatorNoNeed extends StatelessWidget { return Stack( children: [ _MyIndicator( + // Pass the indicator's progress value and loading state to custom indicator widget. value: controller.value, loading: controller.state.isLoading, ), + // Translate the child widget vertically based on the progress of the refresh indicator. Transform.translate( offset: Offset(0, controller.value * 50), child: child, @@ -33,39 +39,44 @@ class RefreshIndicatorNoNeed extends StatelessWidget { ], ); }, + // Function to trigger the refresh when the user pulls to refresh. onRefresh: onRefresh, - child: child, + child: child, // Pass the child widget to be wrapped by the refresh indicator. ); } } +/// A custom indicator widget that displays a message based on the refresh progress. +/// +/// This widget is shown when the refresh indicator is active and shows a "no need" message. class _MyIndicator extends StatelessWidget { - final double value; - final bool loading; + final double value; // The progress value of the refresh indicator. + final bool loading; // The loading state of the refresh indicator. const _MyIndicator({ super.key, - required this.value, - required this.loading, + required this.value, // The current progress value (from 0 to 1). + required this.loading, // Whether the indicator is currently loading. }); @override Widget build(BuildContext context) { - if (value == 0) return Container(); + if (value == 0) return Container(); // Return empty container if no progress is made. + return Padding( padding: const EdgeInsets.only(top: 28), child: Row( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - padding: const EdgeInsets.fromLTRB(20, 10, 20, 10), + padding: const EdgeInsets.fromLTRB(20, 10, 20, 10), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: Palette.extraDarkGray, + borderRadius: BorderRadius.circular(20), + color: Palette.extraDarkGray, ), child: const Text( - 'no need 😉', - style: TextStyle(color: Palette.white, fontSize: 18), + 'no need 😉', // The custom message displayed when the refresh indicator is active. + style: TextStyle(color: Palette.white, fontSize: 18), // Text style for the message. ), ), ],