81 lines
2.6 KiB
Dart
81 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:zenith/chats.dart';
|
|
import 'package:zenith/zenith_client_provider.dart';
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
const LoginPage({super.key});
|
|
|
|
@override
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
final serverController = TextEditingController();
|
|
final usernameController = TextEditingController();
|
|
final passwordController = TextEditingController();
|
|
|
|
void connectMatrix() async {
|
|
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
|
await provider.initialize(serverController.text, usernameController.text,
|
|
passwordController.text);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
prefs.setString("homeserver", serverController.text);
|
|
prefs.setString("username", usernameController.text);
|
|
prefs.setString("password", passwordController.text);
|
|
|
|
if (!mounted) return;
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const ChatsPage()),
|
|
(route) => false);
|
|
}
|
|
|
|
@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),
|
|
),
|
|
);
|
|
}
|
|
}
|