2024-06-26 16:31:03 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-06-26 17:33:03 +00:00
|
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
2024-06-26 16:31:03 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-06-26 17:33:03 +00:00
|
|
|
import 'package:solian/exts.dart';
|
|
|
|
import 'package:solian/providers/account_status.dart';
|
2024-06-26 16:31:03 +00:00
|
|
|
|
2024-06-26 17:33:03 +00:00
|
|
|
class AccountStatusAction extends StatefulWidget {
|
2024-06-26 16:31:03 +00:00
|
|
|
final bool hasStatus;
|
|
|
|
|
|
|
|
const AccountStatusAction({super.key, this.hasStatus = false});
|
|
|
|
|
2024-06-26 17:33:03 +00:00
|
|
|
@override
|
|
|
|
State<AccountStatusAction> createState() => _AccountStatusActionState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AccountStatusActionState extends State<AccountStatusAction> {
|
|
|
|
bool _isBusy = false;
|
|
|
|
|
2024-06-26 16:31:03 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-26 17:33:03 +00:00
|
|
|
final StatusProvider controller = Get.find();
|
|
|
|
|
2024-06-26 16:31:03 +00:00
|
|
|
return SizedBox(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'accountChangeStatus'.tr,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
2024-06-26 17:33:03 +00:00
|
|
|
if (_isBusy)
|
|
|
|
const LinearProgressIndicator()
|
|
|
|
.paddingOnly(bottom: 14)
|
|
|
|
.animate()
|
|
|
|
.slideY(curve: Curves.fastEaseInToSlowEaseOut),
|
|
|
|
SizedBox(
|
|
|
|
height: 48,
|
2024-06-26 16:31:03 +00:00
|
|
|
child: ListView(
|
2024-06-26 17:33:03 +00:00
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
children: StatusProvider.presetStatuses.entries
|
|
|
|
.map(
|
|
|
|
(x) => ActionChip(
|
|
|
|
avatar: x.value.$1,
|
|
|
|
label: Text(x.value.$2),
|
|
|
|
tooltip: x.value.$3,
|
|
|
|
onPressed: _isBusy
|
|
|
|
? null
|
|
|
|
: () async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
await controller.setStatus(
|
|
|
|
x.key,
|
|
|
|
x.value.$2,
|
|
|
|
0,
|
|
|
|
isInvisible: x.key == 'invisible',
|
|
|
|
isSilent: x.key == 'silent',
|
|
|
|
);
|
|
|
|
Navigator.of(context).pop(true);
|
|
|
|
} catch (e) {
|
|
|
|
context.showErrorDialog(e);
|
|
|
|
}
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
},
|
|
|
|
).paddingOnly(right: 6),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
).paddingSymmetric(horizontal: 18),
|
2024-06-26 16:31:03 +00:00
|
|
|
),
|
2024-06-26 17:33:03 +00:00
|
|
|
const Divider(thickness: 0.3, height: 0.3)
|
|
|
|
.paddingSymmetric(vertical: 16),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: widget.hasStatus
|
|
|
|
? const Icon(Icons.edit)
|
|
|
|
: const Icon(Icons.add),
|
|
|
|
title: Text('accountCustomStatus'.tr),
|
|
|
|
onTap: _isBusy ? null : () {},
|
|
|
|
),
|
|
|
|
if (widget.hasStatus)
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Icons.clear),
|
|
|
|
title: Text('accountClearStatus'.tr),
|
|
|
|
onTap: _isBusy
|
|
|
|
? null
|
|
|
|
: () async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
await controller.clearStatus();
|
|
|
|
Navigator.of(context).pop(true);
|
|
|
|
} catch (e) {
|
|
|
|
context.showErrorDialog(e);
|
|
|
|
}
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
},
|
|
|
|
),
|
2024-06-26 16:31:03 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|