import 'package:flutter/material.dart'; import 'package:matrix/matrix.dart'; class LoginPage extends StatefulWidget { const LoginPage({super.key}); @override State createState() => _LoginPageState(); } class _LoginPageState extends State { final serverController = TextEditingController(); final usernameController = TextEditingController(); final passwordController = TextEditingController(); void connectMatrix() async { debugPrint("Making the client..."); final client = Client("zenith"); client.onLoginStateChanged.stream.listen((event) { debugPrint("LoginState=${event.toString()}"); }); debugPrint("Checking the homeserver..."); await client.checkHomeserver(Uri.parse(serverController.text)); debugPrint("Logging in..."); await client.login(LoginType.mLoginPassword, identifier: AuthenticationUserIdentifier(user: usernameController.text), password: passwordController.text); for (var room in client.rooms) { debugPrint( "Room ID: ${room.id}, Room Name: ${room.getLocalizedDisplayname()}"); } } @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: const Text("Login"), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextFormField( controller: serverController, decoration: const InputDecoration( labelText: 'Server', hintText: 'https://matrix.org'), ), TextFormField( controller: usernameController, decoration: const InputDecoration( labelText: 'Username', hintText: 'john'), ), TextFormField( controller: passwordController, decoration: const InputDecoration(labelText: 'Password'), obscureText: true, ), ], ), ), ), floatingActionButton: FloatingActionButton( onPressed: connectMatrix, tooltip: 'Log in', child: const Icon(Icons.login), ), ); } }