Skip to content

Duration extentions

Mohamed Dawood edited this page Mar 30, 2021 · 6 revisions

duration extentions

  • format
   print(Duration(hours: 16767).format()); // one year & 11 months
   //you can also pass your own formatter or one of ready formatters 
   print(Duration(hours: 16767).format(formatter:ArabicEnglishDurationFormatter()))); // one year & 11 months
   // to create your own formatter implement `DurationFormatter`
  • formatWith

to use this extension you have to add SimpleLocalizations.delegate in your localizationsDelegates

   return MaterialApp(
     localizationsDelegates: [
        SimpleLocalizations.delegate,
        ...other delegates
     ],
     supportedLocales: SimpleLocalizations.supportedLocales,
     home: MyApplicationHome(),
   );

no you can use it

   print(Duration(hours: 16767).formatWith(context)); // one year and 11 months if your locale is english
   print(Duration(hours: 16767).formatWith(context)); // عام واحد و١١ شهر if your locale is arabic
  • countDownMicroseconds
  • countDownMilliseconds
  • countDownSeconds
  • countDownMinutes
  • countDownHours
  • countDownDays
  • countUpMicroseconds
  • countUpMilliseconds
  • countUpSeconds
  • countUpMinutes
  • countUpHours
  • countUpDays
   print(Duration(seconds: 100).countDownSeconds()); // Duration(seconds: 99)
   print(Duration(seconds: 100).countUpSeconds()); // Duration(seconds: 101)
Clone this wiki locally