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 to Hire a Full Stack Developer for Frontend Web Development?

People are often heard nowadays talking about back end and front end or sometimes the server side and the client side. The proper presentation of the data to the users is included in the frontends. The users mainly access the web through the normal browser. So, to target the end users, various technologies like JavaScript, CSS, and HTML are used. The  full stack web developer  and full stack programmer is mainly involved in the overall task of development, and so, it may be considered as the proper answer to the question, “What is full stack developer?” The backend generally, on the other hand, is much more concerned with the data aspect of a web application and also with the business logic. The 3-tier architecture For web development, there is mainly three-tier architecture which proves very much useful. Common client-server software architecture is implemented in this particular approach. Due to its huge demand, it is imperative to learn full stack web develo...

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...

Top excellent Photo Editing Apps for iPhone and Android

 The photograph is always looking to capture picture-perfect images with creating memories. Using smartphones cameras offers great optics with high-resolution and sharp results. Today photographers are increasing as they click high-quality images with excellent resolution. If you’re a beginner and want to click masterpiece, the best we could recommend is to go for the best photo editing app for iPhone and Android to create a great visual strategy. One can also choose a product photography course to include photographic techniques and explain the best photo editing apps they should use. After you pick the best photo editing app, make sure it offers a comprehensive set of tools that make your photos shine. What are the best photo editing apps? After testing dozens of famous applications, we have listed below the best photo editing apps for iPhone and Android . We know that not everyone can shoot a photo with just an Android or iPhone smartphone. Therefore, here come the photo editi...