♻️ Refactored auth system

This commit is contained in:
2024-07-25 01:18:47 +08:00
parent ef58430060
commit 6d92a16a62
38 changed files with 444 additions and 523 deletions

View File

@ -26,9 +26,8 @@ class _RealmDetailScreenState extends State<RealmDetailScreen> {
void checkOwner() async {
final AuthProvider auth = Get.find();
final prof = await auth.getProfile();
setState(() {
_isOwned = prof.body['id'] == widget.realm.accountId;
_isOwned = auth.userProfile.value!['id'] == widget.realm.accountId;
});
}

View File

@ -37,7 +37,7 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
void applyRealm() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
if (auth.isAuthorized.isFalse) return;
if (_aliasController.value.text.isEmpty) randomizeAlias();

View File

@ -244,44 +244,38 @@ class RealmChannelListWidget extends StatelessWidget {
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
return FutureBuilder(
future: auth.getProfile(),
builder: (context, snapshot) {
return RefreshIndicator(
onRefresh: onRefresh,
child: Column(
children: [
ListTile(
leading: const Icon(Icons.add_box),
contentPadding: const EdgeInsets.only(left: 32, right: 8),
tileColor: Theme.of(context).colorScheme.surfaceContainer,
title: Text('channelNew'.tr),
subtitle: Text(
'channelNewInRealmHint'
.trParams({'realm': '#${realm.alias}'}),
),
onTap: () {
AppRouter.instance
.pushNamed(
'channelOrganizing',
extra: ChannelOrganizeArguments(realm: realm),
)
.then((value) {
if (value != null) onRefresh();
});
},
),
Expanded(
child: ChannelListWidget(
channels: channels,
selfId: snapshot.data?.body['id'] ?? 0,
noCategory: true,
),
return RefreshIndicator(
onRefresh: onRefresh,
child: Column(
children: [
ListTile(
leading: const Icon(Icons.add_box),
contentPadding: const EdgeInsets.only(left: 32, right: 8),
tileColor: Theme.of(context).colorScheme.surfaceContainer,
title: Text('channelNew'.tr),
subtitle: Text(
'channelNewInRealmHint'.trParams({'realm': '#${realm.alias}'}),
),
onTap: () {
AppRouter.instance
.pushNamed(
'channelOrganizing',
extra: ChannelOrganizeArguments(realm: realm),
)
],
.then((value) {
if (value != null) onRefresh();
});
},
),
);
},
Expanded(
child: ChannelListWidget(
channels: channels,
selfId: auth.userProfile.value!['id'],
noCategory: true,
),
)
],
),
);
}
}