Add button to change image of chat
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user