flutter_custom_utils

Creator: coderz1093

Last updated:

Add to Cart

Description:

flutter custom utils

Note: This library seamlessly functions across all platforms, ensuring compatibility without any issues.





Returns a URL for a placeholder image with the specified dimensions and colors.
String url = getPlaceHolderImage(w: 200, h: 100, backgroundColor: "FF0000", textColor: "00FF00");
print(url); // Output: https://placehold.co/200x100/FF0000/00FF00.webp
copied to clipboard


Global Overlay Alert: This alert will remain at the top of the screen at all times until it is closed.
cShowAlwaysOnTopAlert(
context: context,
title: "Alert",
message: "Testing...............",
ok: () {
cCloseAlwaysOnTopAlert();
},
);

copied to clipboard


Opens a file picker dialog allowing the user to select an image file, optionally crop it, and then perform actions based on user interaction.
cPickAndCropImage(
context,
cropDisable: false,
aspectRatio: 1.7,
cancelButton: () {
setState(() {
croppedImg = null;
});
Navigator.of(context).pop();
},
okButton: (Uint8List data, String fileName) {
/// selected file name
debugPrint(fileName);
setState(() {
croppedImg = data;
/// Load image to ui using 'Image.memory(croppedImg)'
});
Navigator.of(context).pop();
},
),
copied to clipboard


get device id in all available devices platform (android, ios, windows, linux, mac, web(get info details))
await cGetDeviceId()
copied to clipboard


Takes a screenshot of a widget using a [GlobalKey] and returns it as a [Uint8List] (PNG image).
cTakePicture(GlobalKey);
// wrap with RepaintBoundary then use key to create image
RepaintBoundary(
key: GlobalKey,
child:Text('data'),
)
copied to clipboard


flutter platform

just call these functions anywhere

cIsAndroid
cIsIOS
cIsLinux
cIsWindows
cIsMacOS
cIsWeb
cIsFuchsia
copied to clipboard


flutter url structure

https://repad.dev/splash remove hash from url (https://repad.dev/#/splash)

void main(){
// Here we set the URL strategy for our web app.
cSetPathUrl();
runApp(MyApp());
}
copied to clipboard





Make a responsive gridView by using both 1 and 2


provide discardSize to minus size from calculation



Based on your static design's width, calculate the responsive grid item count.
crossAxisCount: cGetResCrossCountGrid(
context: context,
width: 180,
),
copied to clipboard


For responsive grid item aspect ratio, it should be derived from your static design based on height and width.
childAspectRatio: cGetResGridRatio(
context: context,
height: 165,
width: 180,
),
copied to clipboard


For normal grid aspect ratio > Having this aspect ratio will never break in larger or smaller devices
crossAxisCount: 2,
childAspectRatio: cGetGridRatio(
crossAxisCount: 2,
context: context,
height: 165,
width: 180,
),
copied to clipboard

Your provided height and width determine how it works





cFormUrlEncode({'':''});
copied to clipboard




For duration and delay
void splash() {
// cDays, cHours, cMinutes, cSeconds, cMilliseconds
2.cSeconds.cDelay(() {
// code here
});

// given number in seconds
3.cDelay(() {
// code here
});
}
copied to clipboard






An extension for nullable [TimeOfDay] objects, providing a method to convert them to a formatted string in AM/PM format or display 'Invalid date' if the [TimeOfDay] object is null.

cTimeOfDayToString()

TimeOfDay? timeOfDay = TimeOfDay(hour: 14, minute: 30);
String formattedTime = timeOfDay.cTimeOfDayToString();
print(formattedTime); // Output: "2:30 PM"

timeOfDay = null;
formattedTime = timeOfDay.cTimeOfDayToString();
print(formattedTime); // Output: "Invalid date"
copied to clipboard


This method attempts to parse the input string in both 12-hour and 24-hour time formats and returns a [TimeOfDay] object if parsing is successful, or null if the string cannot be parsed as a valid time.

cToTimeOfDay()

String timeString = "2:30 PM";
TimeOfDay? timeOfDay = timeString.cToTimeOfDay();

if (timeOfDay != null) {
print("Parsed time: $timeOfDay");
} else {
print("Invalid time format");
}
copied to clipboard


This method combines the date part of the current [DateTime] instance with the hour and minute components from the provided [time].

cApplied()

final date = DateTime.now();
final time = TimeOfDay(hour: 15, minute: 30);
final combinedDateTime = date.cApplied(time);
print(combinedDateTime); // Output: 2023-09-15:30:00.000
copied to clipboard


Optionally, you can provide a custom [format] string to specify the desired date format. If [format] is not provided, the default format dd/MM/yyyy will be used.

cGetFormattedDate()

final date = DateTime.now();
final formattedDate = date.cGetFormattedDate(format: 'MM-dd-yyyy');
print(formattedDate); // Output: 09-13-2023
copied to clipboard
OR #
String date = '2023-09-13';
String formattedDate = date.cGetFormattedDate(format: 'MMMM d, y');
// Result: 'September 13, 2023'
copied to clipboard


This method calculates the difference between the current [DateTime] instance and the current date and time and provides an aging description.

cDateToAging()

final pastDate = DateTime(2022, 3, 10);
final agingString = pastDate.cDateToAging();
print(agingString); // Output: "1 year ago"
copied to clipboard
OR #
String date = '2023-08-01T12:34:56';
String agingDescription = date.cDateToAging();
// Result: '1 month ago'
copied to clipboard


Converts a string representation of a date and time into a [DateTime] object.

cGetDateFromString()

// Example date and time string
String dateString = "2023-09-26 14:30:00";
// Attempt to parse the date string into a DateTime object
DateTime? dateTime = dateString.cGetDateFromString();
// Check if parsing was successful
if (dateTime != null) {
print("Parsed DateTime: $dateTime");
} else {
print("Failed to parse the string as DateTime.");
}
copied to clipboard





Get the MediaQuery

context.cIsTablet
context.cSize // getSize(context)
context.cMQuery // mQuery(context)
context.cWidth
context.cHeight
context.cTheme
context.cIsDarkMode
context.cIconColor
context.cTextTheme
context.cOrient // orientation
context.cIsLand // landscape
context.cIsPort // portrait
context.cDevicePixelRatio
copied to clipboard




utils
'text'.cToCapitalized
'text'.cToTitleCase
'text'.cIsLowerCase
'text'.cIsAllCap
'text'.cReverse
'text'.cIsDigit
'text'.cIsEmail
'text'.cIsAlphabetOnly
'text'.cIsPhoneIND
'text'.cIsURL
'text'.cIsPhoneNumber
'true'.cToBoolean // 0,1 also available
'1000'.cToCurrencyIND // ₹ 1,000.00
'1000'.cToCurrency() // ₹ 1,000
000.0.cToDistance // (00 km, 00 m available)
000.0.cToWeight // (00 g, 00 kg available)
copied to clipboard


cGetOffer()
String offer = cGetOffer(offerPrice: 90,ordinalPrice: 100); // 10 %
copied to clipboard


buildString()
final word = cBuildString((sb) {
for (var i = 0; i < 10; i++) {
sb.write(i);
}
}); // 0123456789
copied to clipboard






Get Random item from list
['aa', 'bb', 'cc', 'dd'].cRandomSelect.toString()
copied to clipboard


Get first item from list (if list is empty then result will be null)
['aa', 'bb', 'cc', 'dd'].cFirst
['aa', 'bb', 'cc', 'dd'].cFirstWhere((e)=>(type your condition here)))
copied to clipboard






This extension provides a method to convert a Flutter Color object to its hexadecimal representation with an optional leading hash sign. The resulting hexadecimal string includes the alpha, red, green, and blue components of the color.
final color = Color(0xFF42A5F5);
final hexString = color.cToHex(); // Returns: "#FF42A5F5"
copied to clipboard


This extension provides a method to convert a hexadecimal color code represented as a String into a Flutter Color object. The color code can optionally include a leading hash sign ('#'). If the input color code has 6 or 7 characters (with or without the hash sign), the method will assume it represents a color with an alpha component and append 'ff' to the color code to make it fully opaque.
final colorCode = '#FF42A5F5';
final color = colorCode.cToColor(); // Returns: Color(0xFF42A5F5)
copied to clipboard






A customizable widget that wraps its child with hover and tap functionality.
CClick(
onTap: () => print('Tapped!'),
onHover: (isHovering) => print('Hover state: $isHovering'),
child: Container(
width: 100,
height: 100,
color: Colors.blue,
child: Center(child: Text('Click me')),
),
)
copied to clipboard


Allows you to handle (padding/margin)
Text('data').cPadZero // cMargZero
Text('data').cPadAll(10) // cMargAll
Text('data').cPadOnly(l: 10, r: 10, t: 10, b: 10,) // cMargOnly
Text('data').cPadSymmetric(h: 10, v: 10,), // cMargSymmetric
copied to clipboard


Allows you to handle ClipRRect
Container().cClipAll(10)
Container().cClipHorizontal(l:10, r:10,)
Container().cClipVertical(t:10, b:10,)
Container().cClipOnly(tl: 10, tr: 10, bl: 10, br: 10,)
copied to clipboard


Allows you to insert widgets inside a CustomScrollView
Text('data').cToSliver
copied to clipboard


More widgets
Text('data').cVisible(true)
Text('data').cOpacity(0.3)
Text('data').cAbsorb(true)
Text('data').cShadow()
Text('data').cHero(tag)
Text('data').cSizedBox(h:10,w:10)
copied to clipboard


Allows you to handle Alignment
Text('data').cAlignment(Alignment.topCenter)
Text('data').cPosition(l: 10, r: 10, t: 10, b: 10,)
Text('data').cToCenter
Text('data').cExpand(2)
copied to clipboard


For PreferredSize
Text('data').cPreferSize(20)
Text('data').cAspectRatio(1.2)
copied to clipboard


A set of extensions on the base [Widget] class to add custom banner functionality.
Widget myWidget = ...;
Widget bannerWidget = myWidget.cBanner(
disable: false,
location: BannerLocation.topStart,
message: 'Custom Banner',
color: Colors.red
);
copied to clipboard


Contributers #

Nasif A ( Developer )
Abdulla Ramees PK ( Developer )
Fasna sherin P ( Developer )
Sharun MP ( Developer )
Shimna AO ( Developer )
Nashwa K ( Developer )
Sharafas OM ( Maintainer and Publisher )

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.