1.8 KiB
1.8 KiB
fluffyfluttermatrix
Dead simple Flutter widget to use Matrix.org in your Flutter app.
How to use this
- Use the Matrix widget as root for your widget tree:
import 'package:flutter/material.dart';
import 'package:fluffyfluttermatrix/fluffyfluttermatrix.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FluffyMatrix(
child: MaterialApp(
title: 'Welcome to Flutter'
),
);
}
}
- Access the MatrixState object by calling Matrix.of with your current BuildContext:
Client matrix = Matrix.of(context);
- Connect to a Matrix Homeserver and listen to the streams:
matrix.homeserver = "https://yourhomeserveraddress";
matrix.onLoginStateChanged.stream.listen((bool loginState){
print("LoginState: ${loginState.toString()}");
});
matrix.onEvent.stream.listen((EventUpdate eventUpdate){
print("New event update!");
});
matrix.onRoomUpdate.stream.listen((RoomUpdate eventUpdate){
print("New room update!");
});
final loginResp = await matrix.jsonRequest(
type: "POST",
action: "/client/r0/login",
data: {
"type": "m.login.password",
"user": _usernameController.text,
"password": _passwordController.text,
"initial_device_display_name": "Fluffy Matrix Client"
}
);
matrix.connect(
newToken: loginResp["token"],
newUserID: loginResp["user_id"],
newHomeserver: matrix.homeserver,
newDeviceName: "Fluffy Matrix Client",
newDeviceID: loginResp["device_id"],
newMatrixVersions: ["r0.4.0"],
newLazyLoadMembers: false
);
- Send a message to a Room:
final resp = await jsonRequest(
type: "PUT",
action: "/r0/rooms/!fjd823j:example.com/send/m.room.message/$txnId",
data: {
"msgtype": "m.text",
"body": "hello"
}
);