xdml 0.0.21

  • Readme
  • Changelog
  • Installing
  • 33

Visual XAML for Dart/Flutter #

Use xdml for developing visual dart/flutter app.

Install #

  1. add xdml into your pubspec.yaml
  2. run flutter packages get

Usage #

there is a Demo :

main.xaml

<!DOCTYPE xdml>
<!-- Page -->
<x:Page
        xmlns:x="https://github.com/visual-dart/xdml/wiki/xdml"
        xmlns:bind="https://github.com/visual-dart/xdml/wiki/bind"
        xmlns:flutter="https://github.com/flutter/flutter/wiki"
        path="main.dart"
        class="MyAppState">

    <!-- ReferenceGroup -->
    <x:ReferenceGroup>
        <x:Import path="package:flutter/material.dart"></x:Import>
    </x:ReferenceGroup>

    <!-- PartialVuiew -->
    <x:ViewUnit ref="appBarTpl">
        <AppBar>
            <Text x:slot="title">{{
                'Welcome to Flutter'
                + ' '
                + bind:instance = platformVersion
                + bind:i = titleText
            }}</Text>
        </AppBar>
    </x:ViewUnit>

    <x:ViewUnit ref="fuckYou">fuck you !</x:ViewUnit>
    <!-- ViewBuilder -->
    <x:ViewBuilder
            ref="itemFn"
            params="context, int index"
            vars="ctx = context; ctxStr = context.toString()">
        <x:Execution>print("woshinidie")</x:Execution>
        <x:Execution>print(ctx)</x:Execution>
        <x:Execution>print(ctxStr)</x:Execution>
        <Text x:if="index % 2 == 0">123456</Text>
        <Text x:else="">654321</Text>
    </x:ViewBuilder>

    <!-- Host -->
    <MaterialApp
            x:host="build"
            title="{{ bind:i = titleText }}">
        <Scaffold
                x:slot="home"
                bind:appBar="appBarTpl">
            <ListView.builder
                    x:slot="body"
                    x:if="a == null"
                    itemCount="{{ list.length }}"
                    itemBuilder="{{ itemFn }}" />
            <ListView.builder
                    x:slot="body"
                    x:else-if="a == 34523"
                    itemCount="{{ list.length }}">
                <!-- Inner ViewBuilder -->
                <x:ViewBuilder
                        x:slot="itemBuilder"
                        param-context="BuildContext"
                        param-index="int"
                        var-ctx="666">
                    <x:Execution>print("woshinidie")</x:Execution>
                    <x:Execution>print(ctx)</x:Execution>
                    <Text x:if="index % 2 == 0">123456</Text>
                    <Text x:else="">654321</Text>
                </x:ViewBuilder>
            </ListView.builder>
            <Text
                    x:slot="body"
                    x:else-if="a == 2222">sbdx--wriririrriririri</Text>
            <Column
                    x:slot="body"
                    x:else=""
                    mainAxisAlignment="{{ MainAxisAlignment.center }}">
                <x:NodeList
                        x:slot="children"
                        type="Widget">
                    <x:Virtual._rule value="a is Map<dynamic, dynamic> && a.containsKey('b')" />
                    <Text x:if="bind:virtual = _rule">{{ a['b'] + '2#232#' }}</Text>
                    <Text x:else-if="a == 55">yyyyyyyyyyyy</Text>
                    <Text x:else-if="a == 556">tttttttttttt</Text>
                    <Text x:else-if="a == 999">rrrrrrrrrrrr</Text>
                    <Text x:else-if="a == 876">qqqqqqqqqq</Text>
                    <Text x:if="bind:v = _rule">wwwwwwwwww</Text>
                    <Text x:else-if="a == 5">eeeeeeeeeeeee</Text>
                    <Text x:else="">{{ fuckYou }}</Text>
                    <Text>{{ fuckYou }}</Text>
                </x:NodeList>
            </Column>
        </Scaffold>
    </MaterialApp>

</x:Page>

main.dart

import 'dart:async';
import 'package:flutter/services.dart';
import 'package:xdml/metadata.dart';
import 'package:demo/demo.dart';
import 'package:flutter/material.dart';
import 'main.binding.dart';

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

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}

@Binding('main.xaml')
class MyAppState extends State<MyApp> {
  String platformVersion = 'Unknown';
  final String titleText = 'Hello World';
  int _inner(int v) {
    return 555555 + v;
  }

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await Demo.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;
    setState(() {
      platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    var a = {"a": 23, "b": "2342"};
    print(_inner(a['a']));
    var list = [1, 2, 3, 4, 5, 6, 7, 8];
    var titleText = this.titleText;
    return bindXDML(this, context, a, list, titleText);
  }
}

generated automatically:

main.binding.dart

import 'package:flutter/material.dart';
import 'main.dart';

Widget bindXDML(
    MyAppState __instance, BuildContext context, dynamic a, dynamic list) {
  var appBarTpl = AppBar(
      title: Text('Welcome to Flutter' +
          ' ' +
          __instance.platformVersion +
          __instance.titleText));
  var fuckYou = 'fuck you !';
  var itemFn = (dynamic context, int index) {
    var ctx = context;
    var ctxStr = context.toString();
    print("woshinidie");
    print(ctx);
    print(ctxStr);
    return index % 2 == 0 ? Text('123456') : Text('654321');
  };
  return MaterialApp(
      title: __instance.titleText,
      home: Scaffold(
          appBar: appBarTpl,
          body: a == null
              ? ListView.builder(itemCount: list.length, itemBuilder: itemFn)
              : a == 34523
                  ? ListView.builder(
                      itemCount: list.length,
                      itemBuilder: (BuildContext context, int index) {
                        var ctx = 666;
                        print("woshinidie");
                        print(ctx);
                        return index % 2 == 0 ? Text('123456') : Text('654321');
                      })
                  : a == 2222
                      ? Text('sbdx--wriririrriririri')
                      : Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                              if (a is Map<dynamic, dynamic> &&
                                  a.containsKey('b'))
                                Text(a['b'] + '2#232#')
                              else if (a == 55)
                                Text('yyyyyyyyyyyy')
                              else if (a == 556)
                                Text('tttttttttttt')
                              else if (a == 999)
                                Text('rrrrrrrrrrrr')
                              else if (a == 876)
                                Text('qqqqqqqqqq'),
                              if (a is Map<dynamic, dynamic> &&
                                  a.containsKey('b'))
                                Text('wwwwwwwwww')
                              else if (a == 5)
                                Text('eeeeeeeeeeeee')
                              else
                                Text(fuckYou),
                              Text(fuckYou)
                            ])));
}

Compile and watch #

  1. add an config.yaml into your project
entry: lib
group: com.your.owner.group.name
watch: true
  1. run command flutter packages pub run xdml --config=config.yaml
  2. now check binding files.

Work with hot reload #

In android studio, everything is ok.

If you're using vscode, you have to click hot-reload button to fresh your app manually after file changed.

CHANGELOG #

versions #

0.0.21 #

  • fix problems for pub.dev
  • fix crash of linux

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate xdml

2. Use it

The package has the following executables:


$ xdml

Use this package as a library

1. Depend on it

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


dependencies:
  xdml: ^0.0.21

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:xdml/main.dart';
import 'package:xdml/metadata.dart';
import 'package:xdml/transform.dart';
import 'package:xdml/utils.dart';
import 'package:xdml/xdml/app.dart';
import 'package:xdml/xdml/base.dart';
import 'package:xdml/xdml/binding.dart';
import 'package:xdml/xdml/index.dart';
import 'package:xdml/xdml/paths.dart';
import 'package:xdml/xdml/source.dart';
import 'package:xdml/xdml/vnode.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
63
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
33
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21

Health suggestions

Fix lib/xdml/binding.dart. (-15.25 points)

Analysis of lib/xdml/binding.dart reported 33 hints, including:

line 58 col 20: Unnecessary new keyword.

line 74 col 24: Unnecessary new keyword.

line 75 col 25: Unnecessary new keyword.

line 76 col 29: Unnecessary new keyword.

line 96 col 31: Unnecessary new keyword.

Fix lib/xdml/base.dart. (-7.71 points)

Analysis of lib/xdml/base.dart reported 16 hints, including:

line 54 col 10: Don't explicitly initialize variables to null.

line 56 col 10: Don't explicitly initialize variables to null.

line 69 col 21: Don't explicitly initialize variables to null.

line 81 col 23: Unnecessary new keyword.

line 85 col 24: Unnecessary new keyword.

Fix lib/xdml/index.dart. (-6.31 points)

Analysis of lib/xdml/index.dart reported 13 hints, including:

line 53 col 22: Unnecessary new keyword.

line 60 col 24: Unnecessary new keyword.

line 99 col 12: Unnecessary new keyword.

line 134 col 30: Unnecessary new keyword.

line 143 col 22: Unnecessary new keyword.

Fix additional 7 files with analysis or formatting issues. (-14.31 points)

Additional issues in the following files:

  • lib/xdml/source.dart (10 hints)
  • lib/xdml/app.dart (7 hints)
  • bin/xdml.dart (5 hints)
  • lib/xdml/vnode.dart (3 hints)
  • lib/main.dart (2 hints)
  • lib/metadata.dart (1 hint)
  • lib/xdml/paths.dart (1 hint)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and xdml.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
analyzer ^0.38.1 0.38.5 0.39.2+1
ansicolor ^1.0.2 1.0.2
build ^1.0.0 1.2.2
dart_style ^1.2.10 1.3.3
front_end ^0.1.21 0.1.27 0.1.29
glob ^1.1.7 1.2.0
path ^1.6.2 1.6.4
source_gen ^0.9.0 0.9.4+6
watcher ^0.9.7 0.9.7+13
xml ^3.4.0 3.6.1
yaml ^2.1.15 2.2.0
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
html 0.14.0+3
js 0.6.1+1
kernel 0.3.27 0.3.29
logging 0.11.3+2
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
pedantic 1.9.0
petitparser 2.4.0
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6