From df214a07bc34a27d58a0aea7e40d68bede850b0c Mon Sep 17 00:00:00 2001 From: Inex Code Date: Sun, 2 Jul 2023 18:23:33 +0300 Subject: [PATCH] refactor: Remove unused utils, add duration formatter --- lib/utils/extensions/duration.dart | 30 +++++++++++--------------- lib/utils/route_transitions/basic.dart | 9 -------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/utils/extensions/duration.dart b/lib/utils/extensions/duration.dart index 2c302fb8..0e20b07a 100644 --- a/lib/utils/extensions/duration.dart +++ b/lib/utils/extensions/duration.dart @@ -1,13 +1,12 @@ // ignore_for_file: unnecessary_this -extension DurationFormatter on Duration { - String toDayHourMinuteSecondFormat() => [ - this.inHours.remainder(24), - this.inMinutes.remainder(60), - this.inSeconds.remainder(60) - ].map((final int seg) => seg.toString().padLeft(2, '0')).join(':'); +import 'dart:ui'; - String toDayHourMinuteFormat() { +import 'package:duration/duration.dart'; +import 'package:duration/locale.dart'; + +extension DurationFormatter on Duration { + String toTimezoneOffsetFormat() { final designator = this >= Duration.zero ? '+' : '-'; final Iterable segments = [ @@ -18,15 +17,10 @@ extension DurationFormatter on Duration { return '$designator${segments.first}:${segments.last}'; } -// WAT: https://flutterigniter.com/how-to-format-duration/ - String toHoursMinutesSecondsFormat() => - this.toString().split('.').first.padLeft(8, '0'); - - String toDayHourMinuteFormat2() { - final Iterable segments = [ - this.inHours.remainder(24), - this.inMinutes.remainder(60), - ].map((final int seg) => seg.toString().padLeft(2, '0')); - return '${segments.first} h ${segments.last} min'; - } + String toPrettyString(final Locale locale) => + prettyDuration(this, locale: getDurationLocale(locale)); } + +DurationLocale getDurationLocale(final Locale locale) => + DurationLocale.fromLanguageCode(locale.languageCode) ?? + const EnglishDurationLocale(); diff --git a/lib/utils/route_transitions/basic.dart b/lib/utils/route_transitions/basic.dart index a3148e1d..b72d9a94 100644 --- a/lib/utils/route_transitions/basic.dart +++ b/lib/utils/route_transitions/basic.dart @@ -3,12 +3,3 @@ import 'package:flutter/material.dart'; Route materialRoute(final Widget widget) => MaterialPageRoute( builder: (final BuildContext context) => widget, ); - -Route noAnimationRoute(final Widget widget) => PageRouteBuilder( - pageBuilder: ( - final BuildContext context, - final Animation animation1, - final Animation animation2, - ) => - widget, - );