How to use "as" while exporting a library? - dart

I've a file, foo.dart which is exporting some libraries.
export 'dart:convert'; // Works
export 'dart:math' as math; // Error
But as you can see there's an error while using as in export.

You cannot export a namespace.
Exports cannot have an as.
The effect of an as prefix on an import is to declare a namespace in the library and import the imported library into that namespace.
There is nothing similar you can do for exports because you cannot export a namespace at all, the concept does not exist in the language. You can only export declarations.
This also prevents nested namespaces, which you could get if you could export a namespace, and then import or export it with a new prefix as well.

Related

Agda Installation PLFA Configuration

I am trying to use the Programming Language Foundation with Agda plfa library, however the import does not appear to be working properly.
I have cloned the repository and added the repository path to: ~/.agda/libraries and plfa to ~/.agda/defaults.
When I create a test.agda file and check a single line
module plfa.part1.Naturals where
I get an import error:
You tried to load /Users/johngfisher/Desktop/agda_test/nats.agda
which defines the module plfa.part1.Naturals. However, according to
the include path this module should be defined in
/Users/johngfisher/agda_env/libraries/plfa/src/plfa/part1/Naturals.lagda.md
The file is present in the location the import is coming from so I am unsure of why Agda is unable to find it. Any help would be appreciated.
module plfa.part1.Naturals where
defines a module named plfa.part1.Naturals
Did you mean to type
module test where
open import plfa.part1.Naturals
instead?

Flutter - Is there an effect on having a single import rather than multiple?

Basically I have a lot of widgets and services and stuff, like most people do, that I need to access throughout the app. I was wondering if have a single file with an export of every single file and then just simply importing that one file in every page/file i need to access something rather than just importing specific files that the page needs, will it slow down the app or cause any issues or increase file size, etc... or will it behave the same?
Example
login_page.dart
import '1.dart'
import '2.dart'
home_page.dart
import '2.dart'
import '3.dart'
import '9.dart'
import '10.dart'
settings_page.dart
import '1.dart'
import '2.dart'
import '9.dart'
import '10.dart'
or...
all_imports.dart:
export '1.dart'
export '2.dart'
export '3.dart'
... (up until)
export '10.dart'
in every dart file:
import 'all_imports.dart'
Using 'all_imports.dart' may cause unneeded dependencies but dart knows how to handle dependencies that called but not used.
Same implementation of 'all_imports.dart' is used by flutter team on 'material.dart'
You may wish to just make simple design but when you import 'material.dart' it brings everything to the table ('about.dart', 'app.dart', 'banner.dart') and many others.
I would advise you structure your application using 'all_import.dart' pattern
actually, it dosent make a difference, lets imagine this case
in login_page.dart
import '1.dart'
import '2.dart'
here you are being explicit about the dependencies of this module/file/widget, which means it only uses what it needs. which is better for maintenance and redablity of the modules dependanices.
the other case where you have all of your imports in one file
import 'all_imports.dart'
lets see what happens here:
Dart executes the file all_imports.dart
that file is importing every module that you have listed in that file
so the import calls happend again
which means that wont affect your software's performance if you dont have an all_imports.dart file.
actulally i find that this method(the all_imports.dart) will affect your program in a bad way if any.
why? lets say we have a module A that depends on both module B and module C , you would import them this way
moduleA.dart
import 'moduleB'
import 'moduleC'
the advantages is that the module is now explicit in its dependencies and anyone who looks at this module/file in the future will know what they are.
however
the other method where you have all of your imports in a single all_imports.dart file, will cause unneeded dependencies to be loaded for a certain module
lets have the same example above, module A depends on moduleB and moduleC and you listed them in the all_imports.dart file, it will look like this
export `moduleA'
export 'moduleB'
/// some other modules that you are exporting
and in the moduleA.dart file you import it this way
import 'all_imports.dart`
now
the module A has successfully imported moduleB and moduleC which it needs. BUT, now it has all the other dependancies that it dose not need loaded for it although it only needs moduleA and moduleB.

Error: Don't import implementation files from another package

I am trying to make a custom stepper in Flutter. I copied the implementation of stepper.dart, save my file to my own lib folder and fixed the imports to remove the errors.
import 'package:flutter/src/material/button_theme.dart';
import 'package:flutter/src/material/colors.dart';
import 'package:flutter/src/material/debug.dart';
import 'package:flutter/src/material/flat_button.dart';
import 'package:flutter/src/material/icons.dart';
import 'package:flutter/src/material/ink_well.dart';
import 'package:flutter/src/material/material.dart';
import 'package:flutter/src/material/material_localizations.dart';
import 'package:flutter/src/material/theme.dart';
import 'package:flutter/src/material/typography.dart';
Errors are removed but dart says that "Don't import implementation files from another package."
May I know if it's safe to proceed? OR is there another way to implement custom widgets? Or should I transfer the location of my custom stepper file? Thanks.
Flutter Material Widgets are not meant to be subclassed. Here is what I do to create a customized version of a Widget:
(1) Find the source file of the original widget and copy it to the lib directory of your project.
(you already did that)
(2) remove all import statements from the copied file and insert the line
import 'package:flutter/material.dart'; instead
(3) Check the Dart Analysis for missing packages. To add those click on the unknown (red underlined) class name in the copied source file then hit ALT+Enter and select the context menu entry that offers to add the missing dependency.
(4) Now modify the Widget to your hearts delight.
(5) to use the modified Widget in your project import it like this:
import 'stepper.dart' as my;
(6) You can now access your modified stepper as
my.Stepper stepper = my.Stepper(...);
lib/src from other packages is considered to be private by convention.
The analyzer explains that you shouldn't import such files.
Flutter exports everything it considers public under package:flutter/... anyway. Import these files instead.
See also https://www.dartlang.org/tools/pub/package-layout#implementation-files

How can I decide dynamically the base path of my templates in Angular 2?

Say I have two versions of each template, how can I define the base path of them dinamically so I can use one or the other through configuration?
Basically how do I declare TEMPLATES_PATH so it can be used like this:
component.ts
#Component({
templateUrl: TEMPLATES_PATH + 'template1.html';
})
I tried declaring a constant in my root file but when I import it, it doesn't have a value, maybe I'm importing it or declaring it wrong?
root.ts
export const TEMPLATES_PATH = './somepath/'
component.ts
import {TEMPLATES_PATH} from "../../boot";
Perhaps you could use a dedicated file for constants and import it.
I made a test and it works for me with your (constant creation and import).
I think that your problem comes from a circular dependency between modules. The root module imports the component module which imports the root module.
Hope it helps you,
Thierry

The included part ''xclickcounter.dart'' must have a part-of directive

Create a sample web application using the Web UI (web_ui) library, e.g., mylib
open mylib.dart, make it a library:
library mylib;
import 'dart:html';
import 'package:web_ui/web_ui.dart';
part 'xclickcounter.dart';
...
open xclickcounter.dart, remove imports and insert:
part of mylib;
web/out/mylib.dart and web/out/xclickcounter.dart get messed up:
The included part ''xclickcounter.dart'' must have a part-of directive
Classes can only mixin other classes
Mixin can only be applied to class
... more errors follow
What am I doing wrong? Please help :(
Edit: if I don't edit generated sample code, wdc will generate code that falls into separate libraries:
web/out/xclickcounter.dart => x_click_counter
web/out/mylib.dart => mylib_html
Does it mean that if we use web_ui we should not create our own libraries and wdc will do this for us automatically?
Update: if I don't use any library name, similar to what generated sample code does, and only rely on the library names generated by xdc in web/out/... files, I still run into trouble when importing my two components into a 3rd file. Dart Editor will produce the following warning:
The imported libraries 'compa.dart' and 'compb.dart'
should not have the same name
The workaround is to name your libraries based on what xdc produces in web/out/... files, that is:
compa.dart => x-comp-a
compb.dart => x-comp-b
After explicitly placing components into libraries like these the Dart Editor warning disappears.

Resources