GTD Helper

A comprehensive Flutter utility package providing a wide range of helper functions, extensions, and UI components to streamline development.

Features

Error Handling

  • GtdError: Comprehensive error handling with different error types and detailed error information.
  • GtdErrorConstant: Predefined error constants for standardized error handling.

Logging

  • Logger: Flexible logging system with different severity levels (VERBOSE, DEBUG, INFO, WARN, ERROR, WTF).
  • Colored console output for better readability.
  • Configurable log level filtering.

State Management

  • AppBlocObserver: BLoC pattern observer for monitoring state changes, errors, and lifecycle events.

Caching

  • AppSharedPreferences: Simplified interface for SharedPreferences with type-specific getters and setters.
  • CacheHelper: Advanced caching utilities with JSON object serialization/deserialization.

Resource Loading

  • GtdResourceLoader: Utilities for loading string resources from assets and packages.
  • Support for loading content from specific packages with custom paths.

Utility Functions

  • GlobalFunctions:
    • HMAC SHA256 encryption and verification
    • Positional utilities for UI widgets
    • JSON parsing and serialization

Result Pattern

  • Result<S, E>: Implementation of the Result pattern for handling success/error responses.
  • Unit: Utility class representing a void or empty response.

UI Components

  • GtdButton: Customizable button with various states and appearances.
  • GtdPresentViewHelper: Helper for presenting modal views.
  • GtdStickyHeader: Sticky header implementation for lists.
  • GtdHtmlView: HTML content rendering.
  • GtdExpansionView: Customizable expansion panel.
  • GtdGradientIcon: Icon with gradient color.
  • GtdDashBorder: Border with customizable dash patterns.
  • GtdLunarCalendar: Calendar with lunar date support and customizable colors.

Extensions

UI Extensions

  • BuildContextExtension: Convenient extensions for BuildContext.
  • ColorsExtension: Color manipulation (darken, lighten, avg).
  • MaterialStateExtension: Utilities for MaterialState properties.
  • ImageExtension: Image handling utilities.

Data Type Extensions

  • StringExtension: String manipulation and validation.
  • DateTimeExtension: Date formatting, comparison, and manipulation.
  • NumberExtension: Number formatting and conversion.
  • IterableExtension: Collection utilities.
  • GoRouterExtension: Simplified navigation with GoRouter.

List View Extensions

  • LoadMoreListExtension: Infinite scrolling list implementation.
  • GtdPagingScrollPhysics: Custom scroll physics for paged lists.

Network Utilities

  • GtdJsonParser: Safe JSON parsing with error handling.
  • HttpService: HTTP client with standardized request/response handling.

Usage

Error Handling

try {
  // Some operation
} catch (e) {
  final error = GtdError.custom("Custom error message");
  Logger.e(error.message);
}

Logging

// Set log level
Logger.setLogLevel(Logger.INFO);

// Log messages
Logger.v("Verbose message");
Logger.d("Debug message");
Logger.i("Info message");
Logger.w("Warning message");
Logger.e("Error message");

Resource Loading

// Load string from asset
final content = await GtdResourceLoader.loadContentFromResource(
  pathResource: "assets/text/terms.txt"
);

// Load string from package
final htmlContent = await GtdResourceLoader.loadFromPackage(
  packageName: "my_package",
  filePath: "assets/templates/template.html"
);

Caching

// Initialize cache
await AppSharedPreferences.init();

// Save and retrieve data
AppSharedPreferences.putString("key", "value");
final value = AppSharedPreferences.getString("key");

UI Components

Lunar Calendar

GtdLunarCalendar(
  startDate: DateTime.now(),
  mainColor: Colors.blue,
  accentColor: Colors.orange,
  lunarDateMode: GtdLunarDateMode.range,
  bottomBuilder: (context, {startDate, endDate, resetSink}) {
    // Build bottom UI
  },
)

Gradient Icon

GtdGradientIcon(
  Icons.star,
  24.0,
  LinearGradient(
    colors: [Colors.red, Colors.amber],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  ),
)

Extensions

// String extensions
final isValidEmail = "user@example.com".isValidEmail();
final maskedText = "1234567890".maskString(2, 2);

// DateTime extensions
final formattedDate = DateTime.now().localDate("dd/MM/yyyy");
final tomorrow = DateTime.now().addDay(1);

// Color extensions
final darkerColor = Colors.blue.darken(20);
final lighterColor = Colors.red.lighten(30);

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  gtd_helper: ^1.0.6

Requirements

  • Flutter: >=3.13.0
  • Dart: >=3.3.3 <4.0.0

Additional Information

For more examples, check the example project.

Libraries

gtd_helper
helper/app_bloc_observer/app_bloc_observer
helper/cached/app_shared_preferences
helper/cached/cache_helper
helper/custom_ui/gtd_button
helper/custom_ui/gtd_dash_border/gtd_dash_decoration
helper/custom_ui/gtd_dash_border/gtd_dashed_border
helper/custom_ui/gtd_expansion_view
helper/custom_ui/gtd_gradient_icon
helper/custom_ui/gtd_html_view
helper/custom_ui/gtd_list_builder/gtd_alphabet_list
helper/custom_ui/gtd_list_builder/gtd_custom_alphabet_list
helper/custom_ui/gtd_list_builder/gtd_horizontal_sliver_list
helper/custom_ui/gtd_list_builder/gtd_paging_scroll_physics
helper/custom_ui/gtd_lunar_calendar/gtd_calendar_helper
helper/custom_ui/gtd_lunar_calendar/gtd_date_picker_view/gtd_date_range_picker
helper/custom_ui/gtd_lunar_calendar/gtd_date_picker_view/gtd_lunar_date
helper/custom_ui/gtd_lunar_calendar/gtd_luna_converter/gtd_lunar_converter
helper/custom_ui/gtd_lunar_calendar/gtd_lunar_calendar
helper/custom_ui/gtd_present_view_helper
helper/custom_ui/gtd_sticky_header
helper/data_loader/resource_loader
helper/extension/build_context_extension
helper/extension/colors_extension
helper/extension/date_time_extension
helper/extension/go_router_extension
helper/extension/gtd_tuple
helper/extension/image_extension
helper/extension/iterable_extension
helper/extension/loadmore_list_extention
helper/extension/material_state_extension
helper/extension/number_extension
helper/extension/string_extension
helper/global_functions
helper/gtd_app_logger
helper/gtd_call_back
helper/gtd_error_constant
helper/helper
helper/tools/generate_image_enum
helper/version
helper/wrapped_result/result
helper/wrapped_result/unit