hyper 1.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • 55

hyper #

Hyper makes it easy to build HTML using Dart. It's intentionally kept simple, and produces nothing but strings of HTML.

Usage #

import 'package:hyper/hyper.dart';

main() {
  // Create elements using `hyper`, a tag name, attributes, and a list of
  // child elements.
  var header = hyper(
    attrs: {'class': 'header'},
    children: [
      // `t` produces a special element that does not use a tag. Use it for
      // text nodes.
      t('Hello, world!'),
  print(header); // <h1 class="header">Hello, world!</h1>

Hyper Elements #

hyper also has an optional export that includes all of the HTML tags as individual functions. This makes it a little easier to ensure that you're not doing something silly like passing a child element to an img tag.

import 'package:hyper/hyper.dart';
import 'package:hyper/elements.dart' as h;

main() {
  var header = h.h1(
    attrs: {
      'class': 'header',
    children: [
      t('Hello, world!'),
  print(header); // <h1 class="header">Hello, world!</h1>

  // This won't even compile!
  // var invalidElement = h.img(children: [t('Not gonna work!')]);

What this package isn't #

hyper is a tool to make it easier to generate static HTML. It doesn't provide anything exciting like virtual DOM or event listeners. It's simple, and just generates a text HTML string.

Prior Art #

hyper was heavily inspired by HyperScript.

1.0.0 #

  • Initial version, created by Stagehand


import 'package:hyper/hyper.dart';
import 'package:hyper/elements.dart' as h;

main() {
  // Hyper can be used to compose full HTML documents.
  var fullHtmlDoc = hyper('html', children: [
    hyper('head', children: [
      hyper('title', children: [
        t('Hello, world!'),
    hyper('body', children: [
        attrs: {'class': "greeting"},
        children: [
          t('Hello from Hyper!'),
  // <html>
  //   <head>
  //     <title>Hello, world!</title>
  //   </head>
  //   <body>
  //     <h1 class="greeting">Hello from Hyper!</h1>
  //   </body>
  // </html>

  // You can also use the Elements package to make things a bit easier.
  var header = h.header(
    attrs: {'class': 'heading'},
    children: [
      h.h1(children: [
        // Text nodes can be created using t.
  // <header class="heading">
  //   <h1>Title</h1>
  // </header>

  // Using the Elements package also makes sure you don't accidentally pass
  // children to a void element. This won't even compile!
  // var invalidElement = h.img(children: [t('Not gonna work!')]);

  // You can also compose Elements together.
  Element container({List<Element> children}) {
    return h.div(attrs: {'class': 'container'}, children: children);

  Element userProfile(String username, String petsName) {
    return h.div(
      attrs: {'class': 'userProfile'},
      children: [
          attrs: {'class': 'username'},
          children: [
          attrs: {'class': 'petsName'},
          children: [
            t("Parent to: $petsName"),

  var userProfiles = container(
    children: [
      userProfile('dstaley', 'Jpeg'),
      userProfile('paddycarver', 'Roxy'),
  // <div class="container">
  //   <div class="userProfile">
  //     <h2 class="username">dstaley</h2>
  //     <p class="petsName">Parent to: Jpeg</p>
  //   </div>
  //   <div class="userProfile">
  //     <h2 class="username">paddycarver</h2>
  //     <p class="petsName">Parent to: Roxy</p>
  //   </div>
  // </div>

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  hyper: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:hyper/hyper.dart';
Version Uploaded Documentation Archive
1.1.0 Jan 3, 2019 Go to the documentation of hyper 1.1.0 Download hyper 1.1.0 archive
1.0.1 Dec 17, 2018 Go to the documentation of hyper 1.0.1 Download hyper 1.0.1 archive
1.0.0 Dec 17, 2018 Go to the documentation of hyper 1.0.0 Download hyper 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 8, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.0
  • pana: 0.12.15


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:hyper/hyper.dart.

Health suggestions

Format lib/hyper.dart.

Run dartfmt to format lib/hyper.dart.

Format lib/src/hyper_elements.dart.

Run dartfmt to format lib/src/hyper_elements.dart.

Maintenance suggestions

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
build ^1.0.2
build_runner ^1.1.2
code_builder ^3.1.3
dart_style ^1.2.2
source_gen ^0.9.3
test ^1.0.0