2024-06-02 06:42:07 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-07 09:45:44 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-06-02 06:42:07 +00:00
|
|
|
import 'package:get/get.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;
|
2024-08-04 10:13:59 +00:00
|
|
|
dynamic _hasError;
|
2024-06-02 06:42:07 +00:00
|
|
|
|
|
|
|
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-08-04 10:13:59 +00:00
|
|
|
try {
|
2024-09-16 03:57:16 +00:00
|
|
|
final client = await ServiceFinder.configureClient('auth');
|
2024-08-04 10:13:59 +00:00
|
|
|
final resp = await client.get('/users/${widget.name}');
|
|
|
|
if (resp.statusCode == 200) {
|
|
|
|
setState(() {
|
|
|
|
_userinfo = Account.fromJson(resp.body);
|
|
|
|
_isBusy = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
_hasError = resp.bodyString;
|
|
|
|
_isBusy = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
setState(() {
|
|
|
|
_hasError = e;
|
|
|
|
_isBusy = false;
|
|
|
|
});
|
2024-06-02 06:42:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-04 10:13:59 +00:00
|
|
|
Color get _unFocusColor =>
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
|
|
|
|
2024-06-02 06:42:07 +00:00
|
|
|
@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-08-04 10:13:59 +00:00
|
|
|
if (_isBusy) {
|
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
|
|
|
}
|
|
|
|
|
2024-08-04 10:13:59 +00:00
|
|
|
if (_hasError != null) {
|
|
|
|
return SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * 0.75,
|
|
|
|
width: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.cancel, size: 24),
|
2024-09-07 09:45:44 +00:00
|
|
|
const Gap(12),
|
2024-08-04 10:13:59 +00:00
|
|
|
Text(
|
|
|
|
_hasError.toString(),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 13,
|
|
|
|
color: _unFocusColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-09-08 04:32:21 +00:00
|
|
|
profile: _userinfo!.profile,
|
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
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|