Skip to main content

The timezone in Flutter: How To Work With Timezone In Flutter


The DartTime class - In the Dart language Dart allows us to do a lot of things with time from getting the system time to elements the time received from other sources but with the ever-changing list of timezones and daylight savings, the DateTime class is not aware with timezone.

The Google team used the package of them called ‘timezone’ package solves it by making DateTime class timezone aware, which uses IANA time zone databases that make it reliable for use in production code.

Let’s have a look on below steps of How to use timezone with Flutter :

   1. Add the Package into your project’s pubspec.yaml
  • dependencies:         
  • timezone: ^0.5.4

    
   
   2. Install the package
  • Flutter pub get
  
  3. In your terminal navigate to the package’s installation directory
  • If you are using Android Studio then you will be able to navigate the directory just by going to the external libraries section under the project view.
  • Go to dart packages and open timezone in the terminal.
  • Once you open the terminal it will redirect to ‘lib’ folder of the package.
  • But you need to go to one level up.
  • cd...

  4. Download the timezone databases
  • To download the database from IANA the package comes with a handy script.
  • You can find the latest version online and run the script inside the package directory using below command
  • flutter pub run tool/get -s 2019b

  5. Add database into your pubspec.yaml
Assets:
- packages/timezone/data/2019b.tzf

  6.Enable the library
  • Before using the library the database needs to be loaded first and the Github page of the package suggested to do so in the main.dart file.
  • As in my project, I create a TimeHelperService hence I did the setup in the constructor of the class.
               import 'package:timezone/timezone.dart';
               import 'package:flutter/services.dart';
               class TimeHelperService {
               TimeHelperService() {
               setup();
               }
               void setup() async {
               var byteData = await                                   
               rootBundle.load('packages/timezone/data/2019b.tzf');     
              initializeDatabase(byteData.buffer.asUint8List());
              }
              }


   7. Use the library

void convertLocalToDetroit() async { 
             DateTime indiaTime = DateTime.now(); //Emulator time is India time                 final detroitTime = 
             new TZDateTime.from(indiaTime, getLocation('America/Detroit'));                     print('Local India Time: ' + indiaTime.toString()); 
             print('Detroit Time: ' + detroitTime.toString()); }

Final Output: 



        flutter: Local India Time: 2019–09–08 15:25:44.858303
        flutter: Detroit Time: 2019–09–08 05:55:44.858303–0400

So, here are the steps with an output that shows the use of timezone with flutter. There are a number of services that we can provide and here is a small list of our flutter development services


  • Customized app development
  • Enterprise mobile solutions
  • Cross-platform app development
  • Flutter widgets development
  • Flutter app QA & Testing services
  • Custom UI development

Concetto Labs - Flutter Development Company who have great experience in the industry. Just hire flutter app developer from us to build your next android and iOS apps with a single codebase in record time. Not just this, you can get the benefits of cost-saving and willingness to compromise without any overheads.

Comments

  1. Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post.

    Thanks for sharing such a very interesting post with us and keep blogging.

    Inwizards Technology - Flutter App Development Company

    Flutter App Development

    Flutter App Development Company

    ReplyDelete
  2. The Timezone In Flutter: How To Work With Timezone In Flutter >>>>> Download Now

    >>>>> Download Full

    The Timezone In Flutter: How To Work With Timezone In Flutter >>>>> Download LINK

    >>>>> Download Now

    The Timezone In Flutter: How To Work With Timezone In Flutter >>>>> Download Full

    >>>>> Download LINK sy

    ReplyDelete
  3. Thanks for sharing this interesting blog with us. Amazing blog flutter app development services

    ReplyDelete

Post a Comment

Popular posts from this blog

How Much Does It Cost To Hire An App Developer In 2019?

It is considered a very important question that how much it effectively costs for the purpose of hiring an app developer and that too in the year 2019. Nowadays, due to the rising trend, it is very important to hire iPhone developer. Also, it seems that each business, as well as every brand, has its own app in the year 2019. In that way, you can also hire iPhone app developer India. Even, there are many of the local coffee shops which possess an app for the purpose of ordering a frappuccino available at your doorstep or you can collect it on discounts. For developing these apps, sometimes it becomes very important to preferably hire iPhone programmer. There is a gradual presence of many of the IT entrepreneur who is usually making a fortune from a hit app. So, here are given some of the ever-actual issues of how to  hire iPhone app developer  for the development purpose. We will preferably talk about some of the important as well as general tips which can prove helpful to hire io

Engagement Models For Laravel Application Development

  In the mobile app, the development backend holds prime importance. It has a trusted and dependable technology that would take good care of your backend operations with ease. For this purpose, Laravel creator said, “we want to simplify the development process”. Today the Laravel 5.4 is the latest released version that enforces the same ideology with new features. Leverage the best Laravel application development service & create a well-tailored web app. Hire a Laravel development company to scale business growth. Laravel provides predefined architecture and customized backend logic to stand out differently from the crowd. Hire Laravel developers in India and choose the company that understands your needs. We are one of the best leading web application development companies in India. We offer a wide range of engagement models that suits our customer’s needs. Let’s dive into understanding the engagement models in a better way. What are engagement models? An engagement model is a

5 Features while Developing On-Demand ‘Mover n Packers’ App like Uber Movers

Peeping into a few years back, though there were mobiles trending, mobile apps were more limited towards messaging and gaming, but a year or two year back scenario depicts a different story in all. On-demand applications that can be for Food or say Cab Booking or for Salon or for the  Guard booking app  for the event, anything, and everything can be covered in the app itself. UBER is considered more of as a BRAND instead of just an app to book the cab. It has widespread its scope beyond the app in various fields across the globe. Along with the services of moving human from one destination to another, not just limiting to that, Uber is even into Movers and Packers, namely Uber Movers. According to the report, “UberMovers provides free and professional moving services for up to ½ an hour for students in Atlanta between 9 a.m. to 2 p.m. on Saturdays only”. Similar moving services, it provides in Nashville even. Eventually, it is spreading its wings further too. Are you the one prov