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 as you can access all functions and classes of said library by accessing them the way you did in your example: GoogleMap.LatLng.

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;

Leave a Comment