Does Dart have import alias?

Dart doesn’t allow you to rename imported identifiers, but it allows you to specify an import prefix

import '../../constants.dart' as foo;

...

foo.ImportedClass foo = foo.ImportedClass();

It allows also to filter imported identifiers like

import '../../constants.dart' show foo hide bar;

See also

  • https://www.dartlang.org/guides/language/language-tour#libraries-and-visibility
  • What is the difference between “show” and “as” in an import statement?

Barrel files can also make importing easier like

lib/widgets/widgets.dart

export 'widget1.dart';
export 'widget2.dart';
export 'widget3.dart';
export 'widget4.dart';

lib/pages/page1.dart

import '../widgets/widgets.dart';

Widget build(BuildContext context) => Widget1();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)