flutter_msg_engine 0.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 57

flutter_msg_engine

Flutter Message Engine. Flutter 消息引擎。

注册一个消息,在任何地方响应并处理。详细用法参考 example.

Wellcome to star.

Supported Platforms

  • Android
  • IOS

How to Use

# add this line to your dependencies
flutter_picker:
  git: git://github.com/yangyxd/flutter_msg_engine.git

import 'package:flutter_msg_engine/flutter_msg_engine.dart';

// add implements MsgProcessHandler
class MyApp extends StatefulWidget implements MsgProcessHandler<String> {
    ...
    @override
    _MyAppState createState() {
        MsgEngine.instance.register(this, 150);
        return new _MyAppState();
    }

    @override
    void processMsg(MsgPack<String> msg) {
        print("MyApp: " + msg.data);
    }
    ...
}

// register message
MsgEngine.instance.register(this, _msgid);

// unregister message
MsgEngine.instance.unRegister(_msgid);

// start engine
MsgEngine.instance.start();

// stop engine
MsgEngine.instance.stop();

// send message
MsgEngine.instance.sendMsg(MsgPackData<String>(msgId: _msgId, data: "message id is $_msgId"));

LICENSE MIT

0.0.3

Bug repair.

0.0.2

Add registers.

0.0.1

  • TODO: Describe initial release.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_msg_engine/flutter_msg_engine.dart';

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

int SMsgId = 999;
int SMsgRef = 0;

// Use MsgProcessHandler process message.
class MyApp extends StatefulWidget implements MsgProcHandler<String> {

  @override
  _MyAppState createState() {
    MsgEngine.instance.register(this, 150);
    return new _MyAppState();
  }

  @override
  void processMsg(MsgPack<String> msg) {
    print("MyApp: " + msg.data);
  }
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    // message start.
    MsgEngine.instance.start();
    // setting message log callback.
    MsgEngine.instance.onLog = ((MsgEngine engine, String text) {
      print(text);
    });
  }

  @override
  void dispose() {
    super.dispose();
    // stop message engine.
    MsgEngine.instance.stop();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      routes: <String, WidgetBuilder>{
        "/main": (BuildContext context) => new MyHomePage(),
      },
      home: new MyHomePage(title: "HomePage"),
    );
  }

  static _test() {
    MsgEngine.instance.regMsg(111, (MsgPack msg) {
      print(msg.toString());
    });
    MsgEngine.instance.regMsg(115, (MsgPack msg) {
      print("115: ${msg.toString()}");
    });

    MsgEngine.instance.regMsg(118, (MsgPack msg) {
      print("118: ${msg.data}");
    });

    print(MsgEngine().toString());
    MsgPack msg = const MsgBase(msgId: 123, sender: null);
    print("${msg.toString()}");

    MsgEngine.instance.sendMsgSync(const MsgTextBase(msgId: 111, text: "Hello MsgEngine."));
    MsgEngine.instance.sendMsg(const MsgTextBase(msgId: 112, text: "empty"));
    MsgEngine.instance.sendMsg(const MsgTextBase(msgId: 111, text: "Hello MsgEngine 2."));
    MsgEngine.instance.sendMsg(const MsgTextBase(msgId: 113, text: "..."));
    MsgEngine.instance.sendMsg(const MsgTextBase(msgId: 115, text: "Hello MsgEngine 3."));
    MsgEngine.instance.sendMsg(const MsgTextBase(msgId: 150, text: "message 150."));

    MsgEngine.instance.sendMsg(const MsgPackData<int>(msgId: 150, data: 150));
    MsgEngine.instance.sendMsg(const MsgPackData<int>(msgId: 118, data: 520));

    MsgEngine.instance.sendMsg(MsgPackData<String>(msgId: SMsgId - 1, data: "message id is $SMsgRef"));
    MsgEngine.instance.sendMsg(MsgPackData<String>(msgId: SMsgId, data: "message id is $SMsgRef"));

    SMsgRef++;
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> implements MsgProcHandler<String> {
  int _msgid;
  String _msg;

  @override
  void initState() {
    super.initState();
    _msgid = SMsgId;
    SMsgId++;
    MsgEngine.instance.register(this, _msgid);
  }

  @override
  void dispose() {
    super.dispose();
    MsgEngine.instance.unRegister(_msgid);
  }

  @override
  void processMsg(MsgPack<String> msg) {
    print(msg.data);
    setState(() {
      _msg = msg.data;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text(widget.title ?? "New Page")),
      body: new Padding(padding: const EdgeInsets.all(8.0), child: new Wrap(
        direction: Axis.vertical,
        spacing: 8.0,
        children: <Widget>[
          new Text("msgId: $_msgid, Data: $_msg"),
          new FlatButton(onPressed: () {
            _MyAppState._test();
          }, color: Colors.blue, splashColor: Colors.yellow, child: new Text("Test MsgEngine")),
          new MaterialButton(onPressed: () {
            Navigator.pushNamed(context, "/main");
            new Timer(const Duration(milliseconds: 1000), () {
              MsgEngine.instance.sendMsg(MsgPackData<String>(msgId: _msgid, data: "start new page."));
            });
          }, color: Colors.grey, child: new Text("Open New Page"))
        ],
      )),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_msg_engine: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_msg_engine/flutter_msg_engine.dart';
  
Version Uploaded Documentation Archive
0.0.3 Aug 2, 2018 Go to the documentation of flutter_msg_engine 0.0.3 Download flutter_msg_engine 0.0.3 archive
0.0.2 Jul 16, 2018 Go to the documentation of flutter_msg_engine 0.0.2 Download flutter_msg_engine 0.0.2 archive
0.0.1 Jul 4, 2018 Go to the documentation of flutter_msg_engine 0.0.1 Download flutter_msg_engine 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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

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

Dependencies

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