relatica/lib/screens/user_profile_screen.dart

67 wiersze
2.0 KiB
Dart

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../globals.dart';
import '../models/connection.dart';
import '../routes.dart';
import '../services/connections_manager.dart';
import '../utils/url_opening_utils.dart';
class UserProfileScreen extends StatelessWidget {
final String userId;
const UserProfileScreen({super.key, required this.userId});
Future<void> openProfileExternal(
BuildContext context,
Connection connection,
) async {
final openInBrowser =
await showYesNoDialog(context, 'Open profile in browser?');
if (openInBrowser == true) {
await openUrlStringInSystembrowser(
context, connection.profileUrl.toString(), 'Post');
}
}
@override
Widget build(BuildContext context) {
final manager = getIt<ConnectionsManager>();
final body = manager.getById(userId).fold(onSuccess: (profile) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CachedNetworkImage(imageUrl: profile.avatarUrl.toString()),
Text(profile.name),
Text(profile.status.toString()),
ElevatedButton(
onPressed: () => context.pushNamed(
ScreenPaths.userPosts,
params: {'id': profile.id},
),
child: const Text('Posts')),
ElevatedButton(
onPressed: () async => await openProfileExternal(context, profile),
child: const Text('Open In Browser'),
),
],
);
}, onError: (error) {
return Text('Error getting profile: $error');
});
return Scaffold(
appBar: AppBar(
title: Text('Profile'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: body,
),
),
);
}
}