flutter_xmpp 0.0.6 flutter_xmpp: ^0.0.6 copied to clipboard
Flutter XMPP for Realtime Communication, this plugin use Smack Library on Android to connect with XMPP server,currently this plugin still development and will be update ...
flutter_xmpp #
XMPP for realtime chat communication
this plugin just only work for android ..
Not Ready For Production
Getting Started #
Example #
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 _rerceive_message_from = '';
String _rerceive_message_body = '';
FlutterXmpp _FlutterXmpp;
@override
void initState() {
super.initState();
initXmpp();
}
Future<void> initXmpp() async{
var auth = {
"user_jid": "user1@localhost/Android",
"password":"user1_password",
"host":"localhost",
"port":5222
};
_FlutterXmpp = new FlutterXmpp(auth);
await _FlutterXmpp.start(_onReceiveMessage,_onError);
await _FlutterXmpp.send_message("xbon@0.0.0.0","Test Kirim Pesan Darii Android");
LifecycleApp();
}
void LifecycleApp() 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);
setState(() {
_rerceive_message_from = event['from'];
_rerceive_message_body = event['body'];
});
}
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('Status Login: \n$_rerceive_message_from\n$_rerceive_message_body'),
),
),
);
}
}