Primary difference between “Show” and “As” in import statement?

· 3 min read
Primary “show” and “as” Difference in an import statement-min
Primary “show” and “as” Difference in an import statement-min

What is the Difference Between “show” and “as” in an import statement ??

as and show are two different concepts.

With as you are giving the imported library a name. It’s usually done to prevent a library from polluting your namespace if it has a lot of global functions. If you use it as you can access all functions and classes of the said library by accessing them the way you did in your example: GoogleMap.LatLng.

The “Show” define as keywords used in the specific class and used when there is a conflicting class in the imported library.

import 'my_library.dart' as myLib;

With show (and hide) you can pick specific classes you want to be visible in your application. For your example it would be:

import 'package:google_maps/google_maps.dart' show LatLng;

With this you would be able to access LatLng but nothing else from that library. The opposite of this is:

import 'package:google_maps/google_maps.dart' hide LatLng;

With this, you would be able to access everything from that library except for LatLng.

If you want to use multiple classes with the same name you’d need to use as. You also can combine both approaches:

import 'package:google_maps/google_maps.dart' as GoogleMap show LatLng;

show case:

import 'dart:async' show Stream;

This way you only import Stream class from  dart:async, so if you try to use another class dart: async from other than  Stream it will throw an error.

Conclusion:

In this article, we have been through what’s the Difference Between var and dynamic type in Dart ??

Keep Learning !!! Keep Fluttering !!!

Do let us know in the comments if you are still confused in flutter!!

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter Projects, Code libs and etc. Get hire dedicated Flutter developer team from our website & get your project done on time.

Leave a Reply