data_binding 0.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

data_binding #

This is a library of Flutter for data binding works as similar as what Android does.

类Android的Flutter数据绑定库。

How to use #

  1. Create sub class of BaseViewModel with Observables.

​ 创建BaseViewModel的子类,在其中添加多个Observable

  1. Create sub class of BindingWidgetBuilder, which builds Widget with the data from a Observable.

​ 创建BindingWidgetBuilder的子类,其用某个Observable的数据来生成Widget。

  1. binding() the Observable and the BindingWidgetBuilder.

​ 用binding()绑定ObservableBindingWidgetBuilder

  1. When the property of the Observable in the ViewModel was changed, the Widget would be updated.

​ 当ViewModel中的Observableproperty被改变时,Widget也会更新。

UPDATES #

0.2.3- clock 05/03/2019 #

0.2.2- clock 05/03/2019 #

Change license to Apache License 2.0

0.2.1- clock 05/03/2019 #

Change license to BSD 3-clause

0.2.0- clock 05/03/2019 #

  • An Observable can be bound by multi widgets.

0.1.0- clock 05/03/2019 #

  • With example app.

example/lib/main.dart

/*
 * Copyright 2019 chrisfang6
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import 'package:data_binding/base_widget.dart';
import 'package:data_binding/command.dart';
import 'package:data_binding/data_binding.dart';
import 'package:flutter/material.dart';
import 'view_model.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'example for data binding'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  final _viewModel = ViewModel();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            binding(_viewModel.label, LabelWidgetBuilder()),
            binding(_viewModel.clickNumber, NumberWidgetBuilder()),
            binding(_viewModel.clickNumber, NumberWidgetBuilder()),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _viewModel.handle(Command(CommandName.INCREASE.toString(), 1));
        },
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

class LabelWidgetBuilder extends BindingWidgetBuilder<String> {
  @override
  Widget build(String label, {Widget child, BuildContext context}) =>
      Text('$label');
}

class NumberWidgetBuilder extends BindingWidgetBuilder<ClickNumber> {
  @override
  Widget build(ClickNumber clickNumber, {Widget child, BuildContext context}) =>
      Text(
        '${clickNumber.number}',
        style: TextStyle(
          fontSize: 100,
          color: Color(clickNumber.color),
        ),
      );
}

Use this package as a library

1. Depend on it

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


dependencies:
  data_binding: ^0.2.3

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:data_binding/data_binding.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]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

36 out of 36 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.

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test