messages_flutter 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

Messages #

Install #

For Dart or Flutter #

messages_dart: any

Flutter Only #

messages_flutter: any

MessagesPlugin #

All functions is in MessagesPlugin.

Messages #

Messages has 3 implementation:

  • StringMessages - Pure text messages.
  • ErrorMessages - Throwable object and stack trace messages.
  • RoutingMessages - Routable messages.

StringMessage #

var msg = StringMessages("Pure text messages");

ErrorMessages #

void main(){
  try {
    //do something
  } catch (error, stack) {
    ErrorMessages.of(error?.toString(), stack);
  }
    
  Observable.just(data).listen(null, onError: (error, stack){
    ErrorMessages.of(error?.toString(), stack);
  });
}

RoutingMessages #

void main(){
  RoutingMessages.of("login");
  RoutingMessages.of("login", "buttons");
  RoutingMessages.of("login", "buttons", "accountHint");
  RoutingMessages.create([100, 6000, 900001]);
}

Usage #

Prepare Messages Resource File #

Messages Resource file supports any formats which can parse by json like json, yaml, xml or properties.

Base Resource Format

keydescription
messagedisplay message
remarkRemark message
routesChildren routes

Simple Content

{
    "message": "This is a default message",
    "routes": {
        "100": "Hello World!",
        "101": "Goodnight",
        "102": "Yes, I do!",
        "home": "Okay~",
        "login": "What the hell?"
    }
}

Message of routing [100] map to "Hello World!".

Message of routing [home] map to "Okay~".

Message of routing [600] map to "This is a default message".

Complex Content

{
    "message": "This is a default message",
    "routes": {
        "100": {
            "remark": "remark",
            "message": "Hello World!"        
        },
        "101": "Goodnight",
        "102": "Yes, I do!",
        "home": {
            "remark": "home page",
            "message": "Okay~"
        },
        "login": "What the hell?"
    }
}

Message of routing [100] map to "Hello World!".

Remark of routing [100] map to "remark".

Message of routing [home] map to "Okay~".

Remark of routing [home] map to "home page".

Nested Routing

{
    "message": "This is a default message",
    "routes": {
        "100": {
            "remark": "remark",
            "message": "Hello World!",
            "routes": {
                "5000": "Apple is red",
                "6000": "Banana is yellow"
            }  
        },
        "101": "Goodnight",
        "102": "Yes, I do!",
        "home": {
            "remark": "home page",
            "message": "Okay~"
        },
        "login": {
            "message": "What the hell?",
            "routes": {
                "buttons": {
                    "routes": {
                        "accountHint": "Please input account",
                        "passwordHint": {
                            "message": "Please input password"
                        }
                    }
                }
            }
        }
    }
}

Message of routing [100, 5000] map to "Apple is red".

Message of routing [100, 6000] map to "Banana is yellow".

Message of routing [100, 6000, 99000] map to "Banana is yellow".

Message of routing [100, 9000] map to "Hello World!".

Message of routing [login, buttons, accountHint] map to "Please input account".

Load Messages Resource File #

Raw Json

void main(){
  File resource = File("filepath");
  String json = resource.readAsStringSync();
  
  MessagesPlugin.loadAsString(json);
  // or
  JsonElement jsonElement = JsonElement.fromJsonString(json);
  MessagesPlugin.load(jsonElement);
}

Yaml

Add dependency to pubspec.yaml

dependencies:
  yaml: ^2.2.0
import 'dart:convert';
import 'package:yaml/yaml.dart' as yaml;

void main(){
  File resource = File("filepath");
  String content = resource.readAsStringSync();
  
  var doc = yaml.loadYaml(content);
  String json = json.encode(doc);
  
  MessagesPlugin.loadAsString(json);
  // or
  JsonElement jsonElement = JsonElement.fromJsonString(json);
  MessagesPlugin.load(jsonElement);
}

Xml

Add dependency to pubspec.yaml

dependencies:
  xml2json: ^4.1.1
import 'dart:convert';
import 'package:xml2json/xml2json.dart';

void main(){
  File resource = File("filepath");
  String content = resource.readAsStringSync();
  
  var xml2Json = Xml2Json();
  xml2Json.parse(content);
  String json = json.encode(xml2Json.toGData());
  
  MessagesPlugin.loadAsString(json);
  // or
  JsonElement jsonElement = JsonElement.fromJsonString(json);
  MessagesPlugin.load(jsonElement);
}

Throw and Handle Error #

void main(){
  MessagesPlugin.loadAsString(jsonEncode(msg));

  MessagesPlugin.setErrorHandler((Messages messages) {
    print("Custom Handle message: ${messages.message}");
  });
  MessagesPlugin.setErrorTransformer((error, [stack]) {
    if (error is int) return StringMessages("int: $error");
    return StringMessages(error?.toString());
  });

  Future.sync(() {
    // do something
    throw RoutingMessages.of(100, 5000);
  }).catchError(MessagesPlugin.errorHandler).then((_) {
    throw 100;
  }).catchError(MessagesPlugin.errorHandler).then((_){
    throw "An Error~";
  }).catchError(MessagesPlugin.errorHandler);
}

Get Message from Routing #

var msg = RoutingMessages(100, 5000).message;

Extensions #

Getting as RoutingMessages

void main(){
  // list extension for routing
  RoutingMessages routingMessages = [100, 5000].toRoutingMessages();
}

Routing Message

void main(){
  var message = [100, 5000].routingMessage;
  message = ["login", "buttons", "accountHint"].routingMessage;
}

Error Handler

void main(){
  Future.sync(() {
    throw 100;
  }).catchErrorDefault().then((_) {
    throw [100, 5000].toRoutingMessages();
  }).catchErrorDefault();
}

Display

void main() {
  MessagesPlugin.display("Hello World");
  MessagesPlugin.displayString("Hello World");
  MessagesPlugin.displayError("An Error");
  MessagesPlugin.displayRouting(100, 5000);
  
  // messages extension
  Messages messages = StringMessages("Hello World");
  messages.display();
  
  // list extension for routing
  [100, 5000].display();  
}

[1.0.0] - TODO: Add release date. #

  • TODO: Describe initial release.

[1.0.1] #

  • Update readme.md

[1.0.3] #

  • Remove fluttertoast dependency and instead of MessagesPlugin.setDelegate(Future<bool> Function(String message)) to implement messages show.

[1.0.4] #

example/main.dart

import 'package:messages_flutter/messages_flutter.dart';

void main() {

}

Use this package as a library

1. Depend on it

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


dependencies:
  messages_flutter: ^1.0.4

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:messages_flutter/messages_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
71
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)

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

Format lib/src/messages_extension.dart.

Run flutter format to format lib/src/messages_extension.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
messages_dart ^1.0.1 1.0.3
Transitive dependencies
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
xson 1.0.4