2021-09-24 15:51:33 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-09-24 15:51:33 +02:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:vrouter/vrouter.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
|
|
|
import 'package:fluffychat/widgets/content_banner.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-09-24 15:51:33 +02:00
|
|
|
import '../utils/localized_exception_extension.dart';
|
|
|
|
|
|
|
|
class ProfileBottomSheet extends StatelessWidget {
|
|
|
|
final String userId;
|
|
|
|
final BuildContext outerContext;
|
|
|
|
const ProfileBottomSheet({
|
2022-01-28 18:21:20 +01:00
|
|
|
required this.userId,
|
|
|
|
required this.outerContext,
|
|
|
|
Key? key,
|
2021-09-24 15:51:33 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
void _startDirectChat(BuildContext context) async {
|
2021-10-10 10:43:50 +02:00
|
|
|
final client = Matrix.of(context).client;
|
2021-09-24 15:51:33 +02:00
|
|
|
final result = await showFutureLoadingDialog<String>(
|
|
|
|
context: context,
|
2021-11-13 11:54:23 +01:00
|
|
|
future: () => client.startDirectChat(userId),
|
2021-09-24 15:51:33 +02:00
|
|
|
);
|
|
|
|
if (result.error == null) {
|
2022-01-28 18:21:20 +01:00
|
|
|
VRouter.of(context).toSegments(['rooms', result.result!]);
|
2021-09-24 15:51:33 +02:00
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Center(
|
2021-10-14 18:09:30 +02:00
|
|
|
child: SizedBox(
|
2021-09-24 15:51:33 +02:00
|
|
|
width: min(
|
|
|
|
MediaQuery.of(context).size.width, FluffyThemes.columnWidth * 1.5),
|
|
|
|
child: Material(
|
|
|
|
elevation: 4,
|
|
|
|
child: SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.5),
|
|
|
|
leading: IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.arrow_downward_outlined),
|
2021-09-24 15:51:33 +02:00
|
|
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
2022-01-28 18:21:20 +01:00
|
|
|
tooltip: L10n.of(context)!.close,
|
2021-09-24 15:51:33 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
body: FutureBuilder<Profile>(
|
|
|
|
future:
|
|
|
|
Matrix.of(context).client.getProfileFromUserId(userId),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
final profile = snapshot.data;
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: profile == null
|
|
|
|
? Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
child: snapshot.hasError
|
2022-01-28 18:21:20 +01:00
|
|
|
? Text(snapshot.error!
|
2021-09-24 15:51:33 +02:00
|
|
|
.toLocalizedString(context))
|
2021-10-17 14:15:29 +02:00
|
|
|
: const CircularProgressIndicator
|
|
|
|
.adaptive(strokeWidth: 2),
|
2021-09-24 15:51:33 +02:00
|
|
|
)
|
|
|
|
: ContentBanner(
|
2022-01-29 12:35:03 +01:00
|
|
|
mxContent: profile.avatarUrl,
|
2022-07-08 10:13:44 +02:00
|
|
|
defaultIcon: Icons.account_circle_outlined,
|
2021-09-24 15:51:33 +02:00
|
|
|
client: Matrix.of(context).client,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-01-28 18:21:20 +01:00
|
|
|
title: Text(
|
|
|
|
profile?.displayName ?? userId.localpart ?? ''),
|
2021-09-24 15:51:33 +02:00
|
|
|
subtitle: Text(userId),
|
2021-10-14 18:09:30 +02:00
|
|
|
trailing: const Icon(Icons.account_box_outlined),
|
2021-09-24 15:51:33 +02:00
|
|
|
),
|
2021-10-10 10:43:50 +02:00
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
2021-10-14 18:09:30 +02:00
|
|
|
padding: const EdgeInsets.all(12),
|
2021-10-10 10:43:50 +02:00
|
|
|
child: ElevatedButton.icon(
|
2021-09-24 15:51:33 +02:00
|
|
|
onPressed: () => _startDirectChat(context),
|
2022-01-28 18:21:20 +01:00
|
|
|
label: Text(L10n.of(context)!.newChat),
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.send_outlined),
|
2021-09-24 15:51:33 +02:00
|
|
|
),
|
|
|
|
),
|
2021-10-14 18:09:30 +02:00
|
|
|
const SizedBox(height: 8),
|
2021-09-24 15:51:33 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|