flutter_html_render 0.1.13

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

flutter_html #

A Flutter package for rendering html pug template file as Flutter widgets.

Welcome to join us to improve this project!

Getting Started #

To use this plugin, add flutter_html_render as a dependency in your pubspec.yaml file.


  1. install nodejs package

npm install -g flutter-render

  1. create views folder in project root directory

  2. create views folder in assets

  3. open terminal and excute cmd flutter-render --dir views --out assets/views

  4. add output views folder in pubspec.yaml

Example #

  Column
    Text(text="Hello World")
    ListView(padding=[1,2,3,4])
      each item in list
            Text(text=item.text)


  HtmlRender render;

  Future<String> loadAsset() async {
    return await rootBundle.loadString('assets/views/main.pug.json');
  }

  _hotReload(){
    loadAsset().then((fileStr){
      setState(() {
        render = HtmlRender(fileStr);
      });
    });
  }

  @override
  void initState() {
    super.initState();
    loadAsset().then((fileStr){
      setState(() {
        render = HtmlRender(fileStr);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: render?.toWidget({"list":[{"text":"1"},{"text":"2"}]})
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _hotReload,
        child: Icon(Icons.refresh),
      ),
    );
  }

TAGS #

tips:Style Tag will be added soon!

Column #

  Column(verticalDirection="down")
    Tag
    Tag
    ...

Row #

  Row(verticalDirection="down")
    Tag
    Tag
    ...

Container #

  Container(width=160 height=100 alignment="topCenter" margin=[top,right,bottom,left] padding=[top,right,bottom,left])
    Tag ## only one child is allowed

ListView #


  ListView(padding=[top,right,bottom,left])
    each row in list
      ...
  ListView(padding=[top,right,bottom,left])
    Tag
    Tag
    ...

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_html_render/flutter_html_render.dart';
import 'package:flutter/services.dart' show rootBundle;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  HtmlRender render;

  Future<String> loadAsset() async {
    return await rootBundle.loadString('test/outputs/layout.pug.json');
  }

  @override
  void initState() {
    super.initState();
    loadAsset().then((fileStr){
      setState(() {
        render = HtmlRender(fileStr);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: render?.toWidget({}),
      )
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_html_render: ^0.1.13

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:flutter_html_render/flutter_html_render.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

81 out of 81 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test