Solian/lib/widgets/account/account_profile_popup.dart

94 lines
2.8 KiB
Dart
Raw Normal View History

2024-06-02 06:42:07 +00:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/account.dart';
2024-06-26 17:33:03 +00:00
import 'package:solian/providers/account_status.dart';
2024-07-26 08:53:05 +00:00
import 'package:solian/router.dart';
2024-06-02 06:42:07 +00:00
import 'package:solian/services.dart';
2024-06-03 15:36:46 +00:00
import 'package:solian/widgets/account/account_heading.dart';
2024-06-02 06:42:07 +00:00
class AccountProfilePopup extends StatefulWidget {
2024-08-03 04:29:13 +00:00
final String name;
2024-06-02 06:42:07 +00:00
2024-08-03 04:29:13 +00:00
const AccountProfilePopup({super.key, required this.name});
2024-06-02 06:42:07 +00:00
@override
State<AccountProfilePopup> createState() => _AccountProfilePopupState();
}
class _AccountProfilePopupState extends State<AccountProfilePopup> {
bool _isBusy = true;
Account? _userinfo;
2024-08-03 04:29:13 +00:00
void _getUserinfo() async {
2024-06-02 06:42:07 +00:00
setState(() => _isBusy = true);
2024-07-26 08:53:05 +00:00
final client = ServiceFinder.configureClient('auth');
2024-08-03 04:29:13 +00:00
final resp = await client.get('/users/${widget.name}');
2024-06-02 06:42:07 +00:00
if (resp.statusCode == 200) {
_userinfo = Account.fromJson(resp.body);
setState(() => _isBusy = false);
} else {
context.showErrorDialog(resp.bodyString);
Navigator.pop(context);
}
}
@override
void initState() {
super.initState();
2024-08-03 04:29:13 +00:00
_getUserinfo();
2024-06-02 06:42:07 +00:00
}
@override
Widget build(BuildContext context) {
2024-06-03 15:36:46 +00:00
if (_isBusy || _userinfo == null) {
2024-07-26 08:53:05 +00:00
return SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: const Center(child: CircularProgressIndicator()),
);
2024-06-02 06:42:07 +00:00
}
return SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-06-03 15:36:46 +00:00
AccountHeadingWidget(
avatar: _userinfo!.avatar,
banner: _userinfo!.banner,
name: _userinfo!.name,
nick: _userinfo!.nick,
desc: _userinfo!.description,
2024-07-13 11:09:04 +00:00
detail: _userinfo!,
2024-06-03 15:36:46 +00:00
badges: _userinfo!.badges,
2024-07-26 08:53:05 +00:00
status:
Get.find<StatusProvider>().getSomeoneStatus(_userinfo!.name),
extraWidgets: [
Card(
child: ListTile(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
title: Text('visitProfilePage'.tr),
visualDensity:
const VisualDensity(horizontal: -4, vertical: -2),
trailing: const Icon(Icons.chevron_right),
onTap: () {
AppRouter.instance.goNamed(
'accountProfilePage',
pathParameters: {'name': _userinfo!.name},
);
Navigator.pop(context);
},
),
),
],
2024-06-03 15:36:46 +00:00
).paddingOnly(top: 16),
2024-06-02 06:42:07 +00:00
],
),
);
}
}