Solian/lib/widgets/account/account_profile_popup.dart

71 lines
1.9 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 16:31:03 +00:00
import 'package:solian/providers/status.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 {
final Account account;
const AccountProfilePopup({super.key, required this.account});
@override
State<AccountProfilePopup> createState() => _AccountProfilePopupState();
}
class _AccountProfilePopupState extends State<AccountProfilePopup> {
bool _isBusy = true;
Account? _userinfo;
void getUserinfo() async {
setState(() => _isBusy = true);
final client = GetConnect();
2024-06-02 06:42:07 +00:00
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final resp = await client.get('/api/users/${widget.account.name}');
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();
getUserinfo();
}
@override
Widget build(BuildContext context) {
2024-06-03 15:36:46 +00:00
if (_isBusy || _userinfo == null) {
2024-06-02 06:42:07 +00:00
return const Center(child: CircularProgressIndicator());
}
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,
badges: _userinfo!.badges,
2024-06-26 16:31:03 +00:00
status: Get.find<StatusController>().getSomeoneStatus(_userinfo!.name),
2024-06-03 15:36:46 +00:00
).paddingOnly(top: 16),
2024-06-02 06:42:07 +00:00
],
),
);
}
}