flutter_xmpp 0.0.32

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

flutter_xmpp #

XMPP for realtime chat communication, this plugin just only work for android ..

Still Development #

Getting Started #

Example #

import 'dart:io';

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

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

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

class _MyAppState extends State<MyApp> {
  String rerceiveMessageFrom = '';
  String rerceiveMessageBody = '';

  FlutterXmpp flutterXmpp;

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


  @override
  void dispose() async{
    await flutterXmpp.stop();
    super.dispose();
  }

  Future<void> initXmpp() async{
    var auth = {
      "user_jid": "papua-dev@0.0.0.0/Android",
      "password":"papua-dev",
      "host":"0.0.0.0",
      "port":5222
    };
    flutterXmpp = new FlutterXmpp(auth);

    // login
    await flutterXmpp.login();

    // start listening receive message
    await flutterXmpp.start(_onReceiveMessage,_onError);

    sleep(const Duration(seconds:2)); // just sample wait for get current state

    print(await flutterXmpp.currentState()); // get current state

    // sending Message
    await flutterXmpp.sendMessage("xbon@0.0.0.0","Kirim Pesan Bro","random_id_for_sync_with_sqlite");


    // read Message
    await flutterXmpp.readMessage("xbon@0.0.0.0","random_id_for_sync_with_sqlite");


    // life cycle, if app not active, kill stream get incoming message ..
    lifeCycle();

    // logout
    await flutterXmpp.logout();

  }

  void lifeCycle() async{
    SystemChannels.lifecycle.setMessageHandler((msg) async{
      if(msg == "AppLifecycleState.inactive" || msg == "AppLifecycleState.suspending" ){
        await flutterXmpp.stop();
      }else if(msg == "AppLifecycleState.resumed"){
        await flutterXmpp.start(_onReceiveMessage, _onError);
      }
      print('SystemChannels> $msg');
      return "Lifecycle";
    });
  }

  void _onReceiveMessage(dynamic event) {
    print(event);
    if(event["type"] == "incoming") {
      setState(() {
        rerceiveMessageFrom = event['from'];
        rerceiveMessageBody = event['body'];
        rerceiveMessageBody = event['id']; // chat ID
      });
    } else {
      setState(() {
        rerceiveMessageFrom = event['to'];
        rerceiveMessageBody = event['body'];
        rerceiveMessageBody = event['id']; // chat ID
      });
    }
  }

  void _onError(Object error) {
    print(error);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('FlutterXMPP'),
        ),
        body: Center(
          child: Text('Incoming or Outgoinng Message: \n$rerceiveMessageFrom\n$rerceiveMessageBody'),
        ),
      ),
    );
  }
}

0.0.32 #

  • fix bug

0.0.31 #

  • fix bug

0.0.30 #

  • update github home url

0.0.29 #

  • remove log debug

0.0.28 #

  • fix bug

0.0.27 #

  • fix bug

0.0.24 #

  • Add Read Message Status

0.0.23 #

  • Remove Connstructor

0.0.22 #

  • Separate Login & Logout

0.0.21 #

  • Fix Bug

0.0.20 #

  • Add Rquired ID chat For Sending Message, this is for sync data with local DB (SQLITE) for features Message (Read and Unread) And another Status

0.0.19 #

  • Add Broadcast Receiver

0.0.18 #

  • Fix BUG

0.0.17 #

  • Add outgoing message

0.0.16 #

  • If Send Message, Send to self for notif all user already login in another resource

0.0.14 #

  • Add Current State

0.0.6 #

  • Update Plugin Description

0.0.5 #

  • Update Receiver Message

0.0.1-dev.1 #

  • Update readme

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:io';

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

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

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

class _MyAppState extends State<MyApp> {
  String rerceiveMessageFrom = '';
  String rerceiveMessageBody = '';

  FlutterXmpp flutterXmpp;

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


  @override
  void dispose() async{
    await flutterXmpp.stop();
    super.dispose();
  }

  Future<void> initXmpp() async{
    var auth = {
      "user_jid": "22637@0.0.0.0/Android",
      "password":"22637",
      "host":"0.0.0.0",
      "port":5222
    };
    flutterXmpp = new FlutterXmpp(auth);

    // login
    await flutterXmpp.login();

    // start listening receive message
    await flutterXmpp.start(_onReceiveMessage,_onError);

    sleep(const Duration(seconds:2)); // just sample wait for get current state

    print(await flutterXmpp.currentState()); // get current state

    // sending Message
    await flutterXmpp.sendMessage("1@0.0.0.0","test","random_id_for_sync_with_sqlite");


    // read Message
    await flutterXmpp.readMessage("1@0.0.0.0","random_id_for_sync_with_sqlite");


    // life cycle, if app not active, kill stream get incoming message ..
    lifeCycle();

    // logout
    await flutterXmpp.logout();

  }

  void lifeCycle() async{
    SystemChannels.lifecycle.setMessageHandler((msg) async{
      if(msg == "AppLifecycleState.inactive" || msg == "AppLifecycleState.suspending" ){
        await flutterXmpp.stop();
      }else if(msg == "AppLifecycleState.resumed"){
        await flutterXmpp.start(_onReceiveMessage, _onError);
      }
      print('SystemChannels> $msg');
      return "Lifecycle";
    });
  }

  void _onReceiveMessage(dynamic event) {
    print(event);
    if(event["type"] == "incoming") {
      setState(() {
        rerceiveMessageFrom = event['from'];
        rerceiveMessageBody = event['body'];
        rerceiveMessageBody = event['id']; // chat ID
      });
    } else {
      setState(() {
        rerceiveMessageFrom = event['to'];
        rerceiveMessageBody = event['body'];
        rerceiveMessageBody = event['id']; // chat ID
      });
    }
  }

  void _onError(Object error) {
    print(error);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('FlutterXMPP'),
        ),
        body: Center(
          child: Text('Incoming or Outgoinng Message: \n$rerceiveMessageFrom\n$rerceiveMessageBody'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_xmpp: ^0.0.32

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:flutter_xmpp/flutter_xmpp.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_xmpp/flutter_xmpp.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_xmpp/flutter_xmpp.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_xmpp/flutter_xmpp.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_xmpp/flutter_xmpp.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_xmpp that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

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

Fix lib/flutter_xmpp.dart. (-1.49 points)

Analysis of lib/flutter_xmpp.dart reported 3 hints:

line 25 col 62: Name non-constant identifiers using lowerCamelCase.

line 35 col 67: Name non-constant identifiers using lowerCamelCase.

line 45 col 50: Name non-constant identifiers using lowerCamelCase.

Maintenance suggestions

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.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test