Fred Pallesen
Fred Pallesen

Reputation: 31

Can Web UI template be added to a Dart library package?

The generated sample content for a web_ui applications adds xclickcounter.dart AND xclickcounter.html in the web folder. This is an Application Package.

How may I add these to the lib folder to be used as a package that other pacages will depend on? Is it possible?

Upvotes: 2

Views: 118

Answers (1)

Chris Buckett
Chris Buckett

Reputation: 14398

(TL;DR - just drag the xclickcounter files into a lib folder, and use that package in another package)

Yes, this is possible. You would structure your projects like this:

    xclickcounter/
       pubpec.yaml
       build.dart
       lib/
          xclickcounter.html
          xclickcounter.css
          xclickcounter.dart
       web/
          test.html -- if you wanted to test it in this project

    ...elsewhere...
    myAppProject/
      pubspec.yaml
      build.dart
      web/
        myapp.html
        myapp.dart

myapp's pubspec.yaml would contain

         dependencies:
           xclickcounter:
             path: ..\..[relative_or_absolute]..\xclickcounter
                    [or deploy xclickcounter to git]

myapp.html would contain something like:

<head>
  <link rel="components" href="package:xclickcounter/xclickcounter.html">
</head>
<body>
   <x-click-counter></x-click-counter>
   ...
</body>

Upvotes: 4

Related Questions