2024-05-28 12:13:36 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-28 14:13:23 +00:00
|
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/realm.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
import 'package:solian/providers/content/realm.dart';
|
|
|
|
import 'package:solian/router.dart';
|
|
|
|
import 'package:solian/screens/account/notification.dart';
|
|
|
|
import 'package:solian/theme.dart';
|
|
|
|
import 'package:solian/widgets/account/signin_required_overlay.dart';
|
2024-07-12 14:31:45 +00:00
|
|
|
import 'package:solian/widgets/app_bar_leading.dart';
|
2024-06-22 15:59:11 +00:00
|
|
|
import 'package:solian/widgets/app_bar_title.dart';
|
2024-06-06 12:23:50 +00:00
|
|
|
import 'package:solian/widgets/current_state_action.dart';
|
2024-07-12 13:59:16 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-05-28 12:13:36 +00:00
|
|
|
|
2024-05-28 14:13:23 +00:00
|
|
|
class RealmListScreen extends StatefulWidget {
|
2024-05-28 12:13:36 +00:00
|
|
|
const RealmListScreen({super.key});
|
|
|
|
|
2024-05-28 14:13:23 +00:00
|
|
|
@override
|
|
|
|
State<RealmListScreen> createState() => _RealmListScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RealmListScreenState extends State<RealmListScreen> {
|
|
|
|
bool _isBusy = true;
|
|
|
|
|
|
|
|
final List<Realm> _realms = List.empty(growable: true);
|
|
|
|
|
2024-08-01 17:00:31 +00:00
|
|
|
_getRealms() async {
|
2024-06-29 09:35:18 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
2024-07-24 17:18:47 +00:00
|
|
|
if (auth.isAuthorized.isFalse) return;
|
2024-06-29 09:35:18 +00:00
|
|
|
|
2024-05-28 14:13:23 +00:00
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
final RealmProvider provider = Get.find();
|
|
|
|
final resp = await provider.listAvailableRealm();
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_realms.clear();
|
|
|
|
_realms.addAll(
|
|
|
|
resp.body.map((e) => Realm.fromJson(e)).toList().cast<Realm>(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-08-01 17:00:31 +00:00
|
|
|
_getRealms();
|
2024-05-28 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-28 12:13:36 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-28 14:13:23 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
|
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2024-07-12 13:59:16 +00:00
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2024-07-12 14:37:58 +00:00
|
|
|
leading: AppBarLeadingButton.adaptive(context),
|
2024-07-12 13:59:16 +00:00
|
|
|
title: AppBarTitle('realm'.tr),
|
2024-07-13 10:54:08 +00:00
|
|
|
centerTitle: true,
|
2024-07-12 13:59:16 +00:00
|
|
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
|
|
|
actions: [
|
|
|
|
const BackgroundStateWidget(),
|
|
|
|
const NotificationButton(),
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.add_circle),
|
|
|
|
onPressed: () {
|
|
|
|
AppRouter.instance.pushNamed('realmOrganizing').then(
|
|
|
|
(value) {
|
2024-08-01 17:00:31 +00:00
|
|
|
if (value != null) _getRealms();
|
2024-07-12 13:59:16 +00:00
|
|
|
},
|
|
|
|
);
|
2024-05-28 14:13:23 +00:00
|
|
|
},
|
2024-07-12 13:59:16 +00:00
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-07-24 17:18:47 +00:00
|
|
|
body: Obx(() {
|
|
|
|
if (auth.isAuthorized.isFalse) {
|
|
|
|
return SigninRequiredOverlay(
|
2024-08-01 17:00:31 +00:00
|
|
|
onSignedIn: () => _getRealms(),
|
2024-07-24 17:18:47 +00:00
|
|
|
);
|
|
|
|
}
|
2024-05-28 14:13:23 +00:00
|
|
|
|
2024-07-24 17:18:47 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
|
|
|
Expanded(
|
|
|
|
child: CenteredContainer(
|
|
|
|
child: RefreshIndicator(
|
2024-08-01 17:00:31 +00:00
|
|
|
onRefresh: () => _getRealms(),
|
2024-07-24 17:18:47 +00:00
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: _realms.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final element = _realms[index];
|
2024-08-01 17:00:31 +00:00
|
|
|
return _buildEntry(element);
|
2024-07-24 17:18:47 +00:00
|
|
|
},
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
2024-05-29 12:13:53 +00:00
|
|
|
),
|
2024-07-12 13:59:16 +00:00
|
|
|
),
|
2024-07-24 17:18:47 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-01 17:00:31 +00:00
|
|
|
Widget _buildEntry(Realm element) {
|
2024-05-28 14:13:23 +00:00
|
|
|
return Card(
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
AspectRatio(
|
|
|
|
aspectRatio: 16 / 7,
|
|
|
|
child: Stack(
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
fit: StackFit.expand,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
),
|
|
|
|
const Positioned(
|
|
|
|
bottom: -30,
|
|
|
|
left: 18,
|
|
|
|
child: CircleAvatar(
|
|
|
|
radius: 24,
|
|
|
|
backgroundColor: Colors.indigo,
|
|
|
|
child: FaIcon(
|
|
|
|
FontAwesomeIcons.globe,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
).paddingOnly(bottom: 20),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
title: Text(element.name),
|
|
|
|
subtitle: Text(
|
|
|
|
element.description,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-05-29 14:42:11 +00:00
|
|
|
onTap: () {
|
|
|
|
AppRouter.instance.pushNamed('realmView', pathParameters: {
|
|
|
|
'alias': element.alias,
|
|
|
|
});
|
|
|
|
},
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
).paddingOnly(left: 8, right: 8, bottom: 4);
|
2024-05-28 12:13:36 +00:00
|
|
|
}
|
|
|
|
}
|