xdml 0.0.21

  • Readme
  • Changelog
  • Installing
  • 58

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]
27
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:xdml/main.dart with components: io.

Health suggestions

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

Analysis of lib/xdml/base.dart reported 4 hints:

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 148 col 9: Don't explicitly initialize variables to null.

Fix bin/xdml.dart. (-1.49 points)

Analysis of bin/xdml.dart reported 3 hints:

line 6 col 8: Avoid relative imports for files in lib/.

line 7 col 8: Avoid relative imports for files in lib/.

line 8 col 8: Avoid relative imports for files in lib/.

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

Analysis of lib/xdml/binding.dart reported 1 hint:

line 253 col 13: DO use curly braces for all flow control structures.

Maintenance suggestions

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
ansicolor ^1.0.2 1.0.2
build ^1.0.0 1.2.0
dart_style ^1.2.10 1.3.1
front_end ^0.1.21 0.1.27
glob ^1.1.7 1.1.7
path ^1.6.2 1.6.4
source_gen ^0.9.0 0.9.4+5
watcher ^0.9.7 0.9.7+12
xml ^3.4.0 3.5.0
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.3
csslib 0.16.1
html 0.14.0+3
kernel 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
pedantic 1.8.0+1
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