Skip to content

cuneytaykac/moon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Moon Extension πŸŒ™

A comprehensive Flutter package providing useful extensions for strings, dates, context utilities, and more.

Features

πŸ“± Context Extensions

  • Screen Size Utilities: Easy access to screen dimensions with scaling
  • Padding Utilities: Predefined padding values for consistent spacing
  • Responsive Design: Device type detection and responsive layouts

πŸ“… DateTime Extensions

  • Date Formatting: Multiple date format options
  • Year Utilities: Leap year detection and year formatting

πŸ”€ String Extensions

  • Validation: Email, phone, URL, and numeric validation
  • HTML Processing: Remove HTML tags from strings
  • Phone Formatting: Convert between different phone number formats (with Turkish support)
  • Null Safety: Default value handling for null/empty strings

Installation

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

dependencies:
  moon_extension: ^0.0.1

You can install packages from the command line:

flutter pub add moon_extension

Usage

Import the package

import 'package:moon_extension/moon_extension.dart';

Context Extensions

Screen Size Utilities

// Get screen dimensions
double width = context.screenWidth();
double height = context.screenHeight();

// Get scaled dimensions
double halfWidth = context.screenWidth(0.5);
double halfHeight = context.screenHeight(0.5);

// Get screen size and aspect ratio
Size screenSize = context.screenSize;
double ratio = context.aspectRatio;

Padding Utilities

// Horizontal padding
Container(
  padding: context.horizontal8,
  child: Text('Content'),
)

// Vertical padding
Container(
  padding: context.vertical16,
  child: Text('Content'),
)

// All sides padding
Container(
  padding: context.all16,
  child: Text('Content'),
)

// Symmetric padding
Container(
  padding: context.symmetric16,
  child: Text('Content'),
)

Responsive Design

// Device type detection
if (context.isMobile) {
  // Mobile specific code
} else if (context.isTablet) {
  // Tablet specific code
} else if (context.isDesktop) {
  // Desktop specific code
}

// Responsive padding
Container(
  padding: context.responsivePadding,
  child: Text('Responsive content'),
)

DateTime Extensions

final now = DateTime.now();

// Date formatting
String dateOnly = now.dateTimeFormaterWithDate(); // "25/12/2024"
String withTime = now.dateTimeFormaterWithClock(); // "25/12/2024 14:30"
String yearOnly = now.dateTimeFormaterWithYear(); // "2024"

// UTC formatting
String utcFormat = now.formatDateTimeWithoutMilliseconds(); // "2024-12-25T14:30:00Z"

// Leap year detection
int year = 2024;
bool isLeap = year.isLeapYear; // true

String Extensions

Validation

// Email validation
String? email = "user@example.com";
bool isValidEmail = email.isValidEmail(); // true

// Phone validation
String? phone = "+90 555 123 4567";
bool isValidPhone = phone.isValidPhone(); // true

// URL validation
String? url = "https://example.com";
bool isValidUrl = url.isValidUrl(); // true

// Numeric validation
String? numeric = "12345";
bool isNumeric = numeric.isNumeric(); // true

Null Safety

// Default value handling
String? nullString = null;
String result1 = nullString.orDefault(); // "-"

String? emptyString = "";
String result2 = emptyString.orDefault(); // "-"

String? customDefault = nullString.orDefaultWith("No Data"); // "No Data"

// Null/empty checks
bool isNullOrEmpty = nullString.isNullOrEmpty; // true
bool isNotNullOrEmpty = "Hello".isNotNullOrEmpty; // true

HTML Processing

// Remove HTML tags
String? htmlText = "<p>Hello <strong>World</strong>!</p>";
String cleanText = htmlText.removeHtmlTags(); // "Hello World!"

Phone Formatting

// Convert to international format
String? phone1 = "(555) 123 4567";
String international = phone1.toInternationalFormat(); // "+905551234567"

String? phone2 = "05551234567";
String international2 = phone2.toInternationalFormat(); // "+905551234567"

// Convert to simple format
String? phone3 = "+905551234567";
String simple = phone3.toSimpleFormat(); // "5551234567"

Example

Check out the example directory for a complete demonstration of all features.

To run the example:

cd example
flutter run

Additional Information

Dependencies

This package depends on:

  • intl: ^0.19.0 - For date formatting and internationalization

Platform Support

This package supports all Flutter platforms:

  • βœ… Android
  • βœ… iOS
  • βœ… Web
  • βœ… Windows
  • βœ… macOS
  • βœ… Linux

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for a list of changes and version history.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors