2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2024-07-25 06:42:50 +00:00
|
|
|
import 'package:solian/controllers/post_list_controller.dart';
|
2024-05-19 10:01:00 +00:00
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
import 'package:solian/router.dart';
|
2024-05-25 05:00:40 +00:00
|
|
|
import 'package:solian/screens/account/notification.dart';
|
|
|
|
import 'package:solian/theme.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 14:31:45 +00:00
|
|
|
import 'package:solian/widgets/app_bar_leading.dart';
|
2024-07-09 14:39:44 +00:00
|
|
|
import 'package:solian/widgets/feed/feed_list.dart';
|
2024-07-25 08:08:46 +00:00
|
|
|
import 'package:solian/widgets/posts/post_shuffle_swiper.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-07-12 08:19:54 +00:00
|
|
|
class HomeScreen extends StatefulWidget {
|
|
|
|
const HomeScreen({super.key});
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
@override
|
2024-07-12 08:19:54 +00:00
|
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
2024-05-18 10:17:16 +00:00
|
|
|
}
|
|
|
|
|
2024-07-24 18:00:29 +00:00
|
|
|
class _HomeScreenState extends State<HomeScreen>
|
|
|
|
with SingleTickerProviderStateMixin {
|
2024-07-25 08:08:46 +00:00
|
|
|
late final PostListController _postController;
|
2024-07-24 18:00:29 +00:00
|
|
|
late final TabController _tabController;
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-07-26 06:21:00 +00:00
|
|
|
_postController = PostListController();
|
2024-07-24 18:00:29 +00:00
|
|
|
_tabController = TabController(length: 2, vsync: this);
|
|
|
|
_tabController.addListener(() {
|
|
|
|
switch (_tabController.index) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2024-07-25 08:08:46 +00:00
|
|
|
if (_postController.mode.value == _tabController.index) return;
|
2024-07-25 06:42:50 +00:00
|
|
|
_postController.mode.value = _tabController.index;
|
|
|
|
_postController.reloadAllOver();
|
2024-07-24 18:00:29 +00:00
|
|
|
}
|
|
|
|
});
|
2024-05-18 10:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-07-24 17:43:50 +00:00
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2024-07-25 17:16:32 +00:00
|
|
|
child: Scaffold(
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
child: const Icon(Icons.add),
|
|
|
|
onPressed: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const PostCreatePopup(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
body: NestedScrollView(
|
|
|
|
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
|
|
|
return [
|
|
|
|
SliverAppBar(
|
|
|
|
title: AppBarTitle('home'.tr),
|
|
|
|
centerTitle: false,
|
|
|
|
floating: true,
|
|
|
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
|
|
|
leading: AppBarLeadingButton.adaptive(context),
|
|
|
|
actions: [
|
|
|
|
const BackgroundStateWidget(),
|
|
|
|
const NotificationButton(),
|
|
|
|
SizedBox(
|
|
|
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
2024-07-25 08:08:46 +00:00
|
|
|
),
|
2024-07-25 06:42:50 +00:00
|
|
|
],
|
2024-07-25 17:16:32 +00:00
|
|
|
bottom: TabBar(
|
|
|
|
controller: _tabController,
|
|
|
|
tabs: [
|
|
|
|
Tab(text: 'postListNews'.tr),
|
|
|
|
Tab(text: 'postListShuffle'.tr),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
];
|
|
|
|
},
|
|
|
|
body: Obx(() {
|
|
|
|
if (_postController.isPreparing.isTrue) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
2024-07-25 08:08:46 +00:00
|
|
|
);
|
2024-07-25 17:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TabBarView(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
controller: _tabController,
|
|
|
|
children: [
|
|
|
|
RefreshIndicator(
|
|
|
|
onRefresh: () => _postController.reloadAllOver(),
|
|
|
|
child: CustomScrollView(slivers: [
|
|
|
|
FeedListWidget(
|
2024-07-26 06:21:00 +00:00
|
|
|
controller: _postController.pagingController,
|
|
|
|
),
|
2024-07-25 17:16:32 +00:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
PostShuffleSwiper(controller: _postController),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
2024-05-18 16:56:32 +00:00
|
|
|
),
|
2024-05-18 10:17:16 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-07-09 14:39:44 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2024-07-25 06:42:50 +00:00
|
|
|
_postController.dispose();
|
2024-07-09 14:39:44 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
2024-05-18 10:17:16 +00:00
|
|
|
}
|
2024-07-06 12:55:53 +00:00
|
|
|
|
2024-07-24 17:43:50 +00:00
|
|
|
class PostCreatePopup extends StatelessWidget {
|
2024-07-09 14:39:44 +00:00
|
|
|
final bool hideDraftBox;
|
2024-07-06 19:02:10 +00:00
|
|
|
final Function? onCreated;
|
|
|
|
|
2024-07-24 17:43:50 +00:00
|
|
|
const PostCreatePopup({
|
2024-07-09 14:39:44 +00:00
|
|
|
super.key,
|
|
|
|
this.hideDraftBox = false,
|
|
|
|
this.onCreated,
|
|
|
|
});
|
2024-07-06 12:55:53 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
|
2024-07-24 17:18:47 +00:00
|
|
|
if (auth.isAuthorized.isFalse) {
|
|
|
|
return const SizedBox();
|
|
|
|
}
|
|
|
|
|
2024-07-24 17:43:50 +00:00
|
|
|
final List<dynamic> actionList = [
|
|
|
|
(
|
|
|
|
icon: const Icon(Icons.edit_square),
|
|
|
|
label: 'postEditor'.tr,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
AppRouter.instance.pushNamed('postEditor').then((val) {
|
|
|
|
if (val != null && onCreated != null) onCreated!();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
icon: const Icon(Icons.drafts),
|
|
|
|
label: 'draftBoxOpen'.tr,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
AppRouter.instance.pushNamed('draftBox');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * 0.35,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'postNew'.tr,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
|
|
|
Expanded(
|
|
|
|
child: GridView.count(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
crossAxisCount: 3,
|
|
|
|
children: actionList
|
|
|
|
.map((x) => Card(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius:
|
|
|
|
const BorderRadius.all(Radius.circular(8)),
|
|
|
|
onTap: x.onTap,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
x.icon,
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Text(x.label),
|
|
|
|
],
|
|
|
|
).paddingAll(18),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
).paddingSymmetric(horizontal: 20),
|
2024-07-24 17:18:47 +00:00
|
|
|
),
|
2024-07-24 17:43:50 +00:00
|
|
|
],
|
|
|
|
),
|
2024-07-24 17:18:47 +00:00
|
|
|
);
|
2024-07-06 12:55:53 +00:00
|
|
|
}
|
|
|
|
}
|