✨ Realm posts
This commit is contained in:
@ -161,12 +161,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
),
|
||||
onLongPress: () {},
|
||||
).animate(key: Key('m${item.id}'), autoPlay: true).slideY(
|
||||
curve: Curves.fastEaseInToSlowEaseOut,
|
||||
duration: 350.ms,
|
||||
begin: 0.25,
|
||||
end: 0,
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -165,10 +165,10 @@ class _ContactScreenState extends State<ContactScreen> {
|
||||
feColor: Colors.white,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text(otherside.account.name),
|
||||
title: Text(otherside.account.nick),
|
||||
subtitle: Text(
|
||||
'channelDirectDescription'
|
||||
.trParams({'username': otherside.account.name}),
|
||||
.trParams({'username': '@${otherside.account.name}'}),
|
||||
),
|
||||
onTap: () {
|
||||
AppRouter.instance.pushNamed(
|
||||
|
@ -4,6 +4,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/models/realm.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/services.dart';
|
||||
@ -16,15 +17,16 @@ class PostPublishingArguments {
|
||||
final Post? edit;
|
||||
final Post? reply;
|
||||
final Post? repost;
|
||||
final Realm? realm;
|
||||
|
||||
PostPublishingArguments({this.edit, this.reply, this.repost});
|
||||
PostPublishingArguments({this.edit, this.reply, this.repost, this.realm});
|
||||
}
|
||||
|
||||
class PostPublishingScreen extends StatefulWidget {
|
||||
final Post? edit;
|
||||
final Post? reply;
|
||||
final Post? repost;
|
||||
final String? realm;
|
||||
final Realm? realm;
|
||||
|
||||
const PostPublishingScreen({
|
||||
super.key,
|
||||
@ -73,6 +75,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
if (widget.edit != null) 'alias': widget.edit!.alias,
|
||||
if (widget.reply != null) 'reply_to': widget.reply!.id,
|
||||
if (widget.repost != null) 'repost_to': widget.repost!.id,
|
||||
if (widget.realm != null) 'realm': widget.realm!.alias,
|
||||
};
|
||||
|
||||
Response resp;
|
||||
@ -226,7 +229,18 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(thickness: 0.3),
|
||||
if (widget.realm != null)
|
||||
MaterialBanner(
|
||||
leading: const Icon(Icons.group),
|
||||
leadingPadding: const EdgeInsets.only(left: 10, right: 20),
|
||||
dividerColor: Colors.transparent,
|
||||
content: Text(
|
||||
'postInRealmNotify'
|
||||
.trParams({'realm': '#${widget.realm!.alias}'}),
|
||||
),
|
||||
actions: notifyBannerActions,
|
||||
),
|
||||
const Divider(thickness: 0.3, height: 0.3).paddingOnly(bottom: 8),
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding:
|
||||
@ -245,14 +259,9 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
constraints: const BoxConstraints(minHeight: 56),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
width: 0.3, color: Theme.of(context).dividerColor),
|
||||
),
|
||||
),
|
||||
const Divider(thickness: 0.3, height: 0.3),
|
||||
SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
children: [
|
||||
TextButton(
|
||||
|
@ -154,7 +154,11 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
AppRouter.instance.pushNamed('realmView', pathParameters: {
|
||||
'alias': element.alias,
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
).paddingOnly(left: 8, right: 8, bottom: 4);
|
||||
|
18
lib/screens/realms/realm_detail.dart
Normal file
18
lib/screens/realms/realm_detail.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:solian/models/realm.dart';
|
||||
|
||||
class RealmDetailScreen extends StatelessWidget {
|
||||
final String alias;
|
||||
final Realm realm;
|
||||
|
||||
const RealmDetailScreen({
|
||||
super.key,
|
||||
required this.alias,
|
||||
required this.realm,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
201
lib/screens/realms/realm_view.dart
Normal file
201
lib/screens/realms/realm_view.dart
Normal file
@ -0,0 +1,201 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/pagination.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/models/realm.dart';
|
||||
import 'package:solian/providers/content/post.dart';
|
||||
import 'package:solian/providers/content/realm.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/screens/posts/post_publish.dart';
|
||||
import 'package:solian/theme.dart';
|
||||
import 'package:solian/widgets/posts/post_list.dart';
|
||||
|
||||
class RealmViewScreen extends StatefulWidget {
|
||||
final String alias;
|
||||
|
||||
const RealmViewScreen({super.key, required this.alias});
|
||||
|
||||
@override
|
||||
State<RealmViewScreen> createState() => _RealmViewScreenState();
|
||||
}
|
||||
|
||||
class _RealmViewScreenState extends State<RealmViewScreen> {
|
||||
bool _isBusy = false;
|
||||
String? _overrideAlias;
|
||||
|
||||
Realm? _realm;
|
||||
|
||||
getRealm({String? overrideAlias}) async {
|
||||
final RealmProvider provider = Get.find();
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
if (overrideAlias != null) {
|
||||
_overrideAlias = overrideAlias;
|
||||
}
|
||||
|
||||
try {
|
||||
final resp = await provider.getRealm(_overrideAlias ?? widget.alias);
|
||||
setState(() => _realm = Realm.fromJson(resp.body));
|
||||
} catch (e) {
|
||||
context.showErrorDialog(e);
|
||||
}
|
||||
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
getRealm();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
child: SafeArea(
|
||||
child: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return [
|
||||
SliverOverlapAbsorber(
|
||||
handle:
|
||||
NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: SliverAppBar(
|
||||
title: Text(_realm?.name ?? 'loading'.tr),
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onPressed: () {
|
||||
AppRouter.instance
|
||||
.pushNamed(
|
||||
'realmDetail',
|
||||
pathParameters: {'alias': widget.alias},
|
||||
extra: _realm,
|
||||
)
|
||||
.then((value) {
|
||||
if (value == false) AppRouter.instance.pop();
|
||||
if (value != null) {
|
||||
final resp =
|
||||
Realm.fromJson(value as Map<String, dynamic>);
|
||||
getRealm(overrideAlias: resp.alias);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
||||
),
|
||||
],
|
||||
bottom: const TabBar(
|
||||
isScrollable: true,
|
||||
tabs: [
|
||||
Tab(icon: Icon(Icons.feed)),
|
||||
Tab(icon: Icon(Icons.chat)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
];
|
||||
},
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
if (_isBusy) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return TabBarView(
|
||||
children: [
|
||||
RealmPostListWidget(realm: _realm!),
|
||||
Icon(Icons.directions_transit),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RealmPostListWidget extends StatefulWidget {
|
||||
final Realm realm;
|
||||
|
||||
const RealmPostListWidget({super.key, required this.realm});
|
||||
|
||||
@override
|
||||
State<RealmPostListWidget> createState() => _RealmPostListWidgetState();
|
||||
}
|
||||
|
||||
class _RealmPostListWidgetState extends State<RealmPostListWidget> {
|
||||
final PagingController<int, Post> _pagingController =
|
||||
PagingController(firstPageKey: 0);
|
||||
|
||||
getPosts(int pageKey) async {
|
||||
final PostProvider provider = Get.find();
|
||||
|
||||
Response resp;
|
||||
try {
|
||||
resp = await provider.listPost(pageKey, realm: widget.realm.id);
|
||||
} catch (e) {
|
||||
_pagingController.error = e;
|
||||
return;
|
||||
}
|
||||
|
||||
final PaginationResult result = PaginationResult.fromJson(resp.body);
|
||||
final parsed = result.data?.map((e) => Post.fromJson(e)).toList();
|
||||
if (parsed != null && parsed.length >= 10) {
|
||||
_pagingController.appendPage(parsed, pageKey + parsed.length);
|
||||
} else if (parsed != null) {
|
||||
_pagingController.appendLastPage(parsed);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_pagingController.addPageRequestListener(getPosts);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.post_add),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
tileColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
title: Text('postNew'.tr),
|
||||
subtitle: Text(
|
||||
'postNewInRealmHint'
|
||||
.trParams({'realm': '#${widget.realm.alias}'}),
|
||||
),
|
||||
onTap: () {
|
||||
AppRouter.instance
|
||||
.pushNamed(
|
||||
'postPublishing',
|
||||
extra: PostPublishingArguments(realm: widget.realm),
|
||||
)
|
||||
.then((value) {
|
||||
if (value != null) _pagingController.refresh();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
PostListWidget(controller: _pagingController),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user