Compare commits
3 Commits
1aa73bbd7e
...
128a1bf35f
Author | SHA1 | Date | |
---|---|---|---|
128a1bf35f | |||
a552c30ba0 | |||
2039b4e90d |
|
@ -25,11 +25,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
});
|
});
|
||||||
|
|
||||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
final client = Client("zenith");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.checkHomeserver(Uri.parse(serverController.text));
|
await provider.client.checkHomeserver(Uri.parse(serverController.text));
|
||||||
await client.login(
|
await provider.client.login(
|
||||||
LoginType.mLoginPassword,
|
LoginType.mLoginPassword,
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
identifier: AuthenticationUserIdentifier(user: usernameController.text),
|
||||||
|
@ -54,7 +53,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.setClient(client);
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString("homeserver", serverController.text);
|
prefs.setString("homeserver", serverController.text);
|
||||||
prefs.setString("username", usernameController.text);
|
prefs.setString("username", usernameController.text);
|
||||||
|
|
|
@ -50,16 +50,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
final provider = Provider.of<ZenithClientProvider>(context, listen: false);
|
||||||
final client = Client("zenith");
|
|
||||||
provider.setClient(client);
|
|
||||||
setState(() {
|
setState(() {
|
||||||
showRooms = true;
|
showRooms = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.checkHomeserver(Uri.parse(homeserver));
|
await provider.client.checkHomeserver(Uri.parse(homeserver));
|
||||||
if (!client.isLogged())
|
if (!provider.client.isLogged())
|
||||||
await client.login(LoginType.mLoginPassword,
|
await provider.client.login(LoginType.mLoginPassword,
|
||||||
password: password,
|
password: password,
|
||||||
identifier: AuthenticationUserIdentifier(user: username));
|
identifier: AuthenticationUserIdentifier(user: username));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -28,22 +28,6 @@ class _RoomsPageState extends State<RoomsPage> {
|
||||||
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void fixNames(Client client) async {
|
|
||||||
final rooms = client.rooms
|
|
||||||
.where((element) =>
|
|
||||||
element.getLocalizedDisplayname().contains("Group with"))
|
|
||||||
.toList();
|
|
||||||
for (final room in rooms) {
|
|
||||||
print("Setting power level to 100...");
|
|
||||||
final result = await room.setPower(client.userID!, 100);
|
|
||||||
print("Result=$result");
|
|
||||||
print("Fixing ${room.getLocalizedDisplayname()}...");
|
|
||||||
await room.setName(
|
|
||||||
room.getLocalizedDisplayname().replaceAll(RegExp("Group with"), ""));
|
|
||||||
}
|
|
||||||
print("Fixed all.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -97,21 +81,12 @@ class _RoomsPageState extends State<RoomsPage> {
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Center(child: Consumer<ZenithClientProvider>(
|
child: Center(child: Consumer<ZenithClientProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
print(provider.client.rooms
|
|
||||||
.where((element) =>
|
|
||||||
element.getLocalizedDisplayname().contains("Group with"))
|
|
||||||
.length);
|
|
||||||
|
|
||||||
provider.client.onRoomState.stream.listen((event) {
|
provider.client.onRoomState.stream.listen((event) {
|
||||||
setState(() {
|
setState(() {
|
||||||
loadingRooms = false;
|
loadingRooms = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return ElevatedButton(
|
|
||||||
onPressed: () => fixNames(provider.client),
|
|
||||||
child: const Text("Fix names"));
|
|
||||||
|
|
||||||
if (provider.client.rooms.isEmpty)
|
if (provider.client.rooms.isEmpty)
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
class ZenithClientProvider extends ChangeNotifier {
|
class ZenithClientProvider extends ChangeNotifier {
|
||||||
late Client _client;
|
final client = Client("zenith", databaseBuilder: (_) async {
|
||||||
|
final dir =
|
||||||
Client get client => _client;
|
await getApplicationSupportDirectory(); // Recommend path_provider package
|
||||||
|
final db = HiveCollectionsDatabase('matrix_example_chat', dir.path);
|
||||||
void setClient(Client value) {
|
await db.open();
|
||||||
_client = value;
|
return db;
|
||||||
notifyListeners();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
import FlutterMacOS
|
import FlutterMacOS
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
import path_provider_foundation
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
}
|
}
|
||||||
|
|
26
pubspec.lock
26
pubspec.lock
|
@ -344,6 +344,30 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.3"
|
version: "1.8.3"
|
||||||
|
path_provider:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: path_provider
|
||||||
|
sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
|
path_provider_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_android
|
||||||
|
sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.2"
|
||||||
|
path_provider_foundation:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_foundation
|
||||||
|
sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.1"
|
||||||
path_provider_linux:
|
path_provider_linux:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -623,4 +647,4 @@ packages:
|
||||||
version: "6.3.0"
|
version: "6.3.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.1.5 <4.0.0"
|
dart: ">=3.1.5 <4.0.0"
|
||||||
flutter: ">=3.7.0"
|
flutter: ">=3.10.0"
|
||||||
|
|
|
@ -41,6 +41,7 @@ dependencies:
|
||||||
provider: ^6.1.1
|
provider: ^6.1.1
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
file_picker: ^6.1.1
|
file_picker: ^6.1.1
|
||||||
|
path_provider: ^2.1.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user