Add button to change image of chat

This commit is contained in:
Brandon Presley 2023-12-30 12:41:40 +13:00
parent 7c1e18c4e8
commit 8ca788ccdd
3 changed files with 32 additions and 0 deletions

View File

@ -1,5 +1,7 @@
import 'dart:async';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
@ -34,6 +36,16 @@ class _RoomPageState extends State<RoomPage> {
});
}
void setAvatar() async {
final participants = widget.room.getParticipants();
final picked = await FilePicker.platform.pickFiles(type: FileType.image);
if (picked == null) return;
final file = File(picked.files.single.path!);
final bytes = await file.readAsBytes();
final uri = await widget.room.client.uploadContent(bytes);
await widget.room.client.setAvatarUrl(participants[0].id, uri);
}
@override
void dispose() {
super.dispose();
@ -90,6 +102,9 @@ class _RoomPageState extends State<RoomPage> {
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.room.getLocalizedDisplayname()),
actions: [
IconButton(onPressed: setAvatar, icon: const Icon(Icons.image))
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),

View File

@ -145,6 +145,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6"
url: "https://pub.dev"
source: hosted
version: "6.1.1"
flutter:
dependency: "direct main"
description: flutter
@ -174,6 +182,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
url: "https://pub.dev"
source: hosted
version: "2.0.17"
flutter_test:
dependency: "direct dev"
description: flutter

View File

@ -40,6 +40,7 @@ dependencies:
flutter_openssl_crypto: ^0.3.0
provider: ^6.1.1
shared_preferences: ^2.2.2
file_picker: ^6.1.1
dev_dependencies:
flutter_test: