oh_my_flutter 0.2.0
oh_my_flutter: ^0.2.0 copied to clipboard
Focused Flutter utilities for colors, time, gestures, connectivity, telephony, and WhatsApp links.
oh_my_flutter #
Small, strongly typed utilities for common Flutter application tasks.
Installation #
Add the latest compatible release from pub.dev:
flutter pub add oh_my_flutter
Or add it directly to your pubspec.yaml:
dependencies:
oh_my_flutter: ^0.2.0
Import the public library wherever you need it:
import 'package:oh_my_flutter/oh_my_flutter.dart';
Quick start #
Extensions make common transformations concise while preserving Flutter and Dart types:
import 'package:flutter/material.dart';
import 'package:oh_my_flutter/oh_my_flutter.dart';
final accent = const Color(0xFFFF4A4B);
final lighterAccent = accent.lighten(0.12);
final hex = lighterAccent.toHex();
final oklch = lighterAccent.toOklch();
Utilities #
Present relative time #
Use DateTime.timeAgo when presentation depends on elapsed time but the package
should not own your wording or localization. Callbacks determine both the
result type and the text shown to the user.
final label = publishedAt.timeAgo<String>(
onNow: () => 'now',
onMinutesAgo: (count) => '$count min ago',
onHoursAgo: (count) => '$count hr ago',
onDaysAgo: (count) => '$count days ago',
onMiss: () => 'a while ago',
);
Time is read through package:clock, so applications and tests can pin the
current instant without changing production code. See the API reference
for bucketing and fallback behavior.
Transform colors and work with OKLCH #
Use the color extensions for direct Flutter Color transformations. Convert
to OKLCH when you need perceptually uniform lightness, chroma, and hue values.
final base = const Color(0xFFFF4A4B);
final lighter = base.lighten(0.12);
final darker = base.darken(0.12);
final hex = base.toHex();
final oklch = base.toOklch();
final restored = oklch.toColor();
The API reference documents supported color spaces, gamut mapping, clamping, and alpha behavior.
Classify gesture velocity #
Use the Velocity extension at a drag boundary when release speed and direction
should help decide whether an interaction completes.
void handleDragEnd(DragEndDetails details) {
final shouldDismiss = details.velocity.isSwipeDown();
if (shouldDismiss) {
dismiss();
}
}
The methods classify velocity only. The consuming interaction remains responsible for distance, progress, and whether the action is allowed.
Represent offline Dio failures #
Add OfflineErrorDioInterceptor when callers need to distinguish typed offline
failures from other Dio errors without scattering connectivity probes through
application code.
final dio = Dio()
..interceptors.add(OfflineErrorDioInterceptor());
try {
await dio.get('/jobs');
} on DioException catch (error) {
if (error.isOfflineConnectionDioException) {
showOfflineState();
}
}
The original error remains available as the cause of the typed offline exception. Probe rules and timeout behavior are documented in the API reference.
Launch phone calls and WhatsApp chats #
Use Telephony and Whatsapp at the boundary where application data becomes
an external URI. Both utilities sanitize commonly formatted international
phone numbers and report whether the platform accepted the launch.
await Telephony().call(number: '+55 (11) 98888-7777');
await Whatsapp().launchChat(
number: '+55 (11) 98888-7777',
message: 'Hello! I would like more information.',
);
Always include the country code. These utilities sanitize URI input; they do not verify that a phone number exists.
Documentation #
- Run the complete public-API example.
- Read the generated API reference for contracts, defaults, exceptions, and focused examples.
Scope #
oh_my_flutter provides portable utility APIs. It intentionally does not own
application state, routing, localization, design components, or
application-specific domain logic.