✨ Post detail
This commit is contained in:
parent
49cabd1f39
commit
a673beb87c
@ -37,6 +37,9 @@
|
|||||||
"report": "Report",
|
"report": "Report",
|
||||||
"repost": "Repost",
|
"repost": "Repost",
|
||||||
"reply": "Reply",
|
"reply": "Reply",
|
||||||
|
"untitled": "Untitled",
|
||||||
|
"postDetail": "Post detail",
|
||||||
|
"postNoun": "Post",
|
||||||
"fieldUsername": "Username",
|
"fieldUsername": "Username",
|
||||||
"fieldNickname": "Nickname",
|
"fieldNickname": "Nickname",
|
||||||
"fieldEmail": "Email address",
|
"fieldEmail": "Email address",
|
||||||
@ -84,6 +87,7 @@
|
|||||||
"postRepostingNotice": "You're about to repost a post that posted {}.",
|
"postRepostingNotice": "You're about to repost a post that posted {}.",
|
||||||
"postReact": "React",
|
"postReact": "React",
|
||||||
"postComments": {
|
"postComments": {
|
||||||
|
"zero": "Comment",
|
||||||
"one": "{} comment",
|
"one": "{} comment",
|
||||||
"other": "{} comments"
|
"other": "{} comments"
|
||||||
},
|
},
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
"report": "检举",
|
"report": "检举",
|
||||||
"repost": "转帖",
|
"repost": "转帖",
|
||||||
"reply": "回贴",
|
"reply": "回贴",
|
||||||
|
"untitled": "无题",
|
||||||
|
"postDetail": "帖子详情",
|
||||||
|
"postNoun": "帖子",
|
||||||
"fieldUsername": "用户名",
|
"fieldUsername": "用户名",
|
||||||
"fieldNickname": "显示名",
|
"fieldNickname": "显示名",
|
||||||
"fieldEmail": "电子邮箱地址",
|
"fieldEmail": "电子邮箱地址",
|
||||||
@ -84,6 +87,7 @@
|
|||||||
"postRepostingNotice": "你正在转发由 {} 发布的帖子。",
|
"postRepostingNotice": "你正在转发由 {} 发布的帖子。",
|
||||||
"postReact": "反应",
|
"postReact": "反应",
|
||||||
"postComments": {
|
"postComments": {
|
||||||
|
"zero": "评论",
|
||||||
"one": "{} 条评论",
|
"one": "{} 条评论",
|
||||||
"other": "{} 条评论"
|
"other": "{} 条评论"
|
||||||
},
|
},
|
||||||
|
@ -8,8 +8,10 @@ import 'package:surface/screens/auth/login.dart';
|
|||||||
import 'package:surface/screens/auth/register.dart';
|
import 'package:surface/screens/auth/register.dart';
|
||||||
import 'package:surface/screens/explore.dart';
|
import 'package:surface/screens/explore.dart';
|
||||||
import 'package:surface/screens/home.dart';
|
import 'package:surface/screens/home.dart';
|
||||||
|
import 'package:surface/screens/post/post_detail.dart';
|
||||||
import 'package:surface/screens/post/post_editor.dart';
|
import 'package:surface/screens/post/post_editor.dart';
|
||||||
import 'package:surface/screens/settings.dart';
|
import 'package:surface/screens/settings.dart';
|
||||||
|
import 'package:surface/types/post.dart';
|
||||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
|
|
||||||
final appRouter = GoRouter(
|
final appRouter = GoRouter(
|
||||||
@ -58,6 +60,14 @@ final appRouter = GoRouter(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/post/:slug',
|
||||||
|
name: 'postDetail',
|
||||||
|
builder: (context, state) => PostDetailScreen(
|
||||||
|
slug: state.pathParameters['slug']!,
|
||||||
|
preload: state.extra as SnPost?,
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ShellRoute(
|
ShellRoute(
|
||||||
|
@ -171,7 +171,16 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
|||||||
hasReachedMax: _postCount != null && _posts.length >= _postCount!,
|
hasReachedMax: _postCount != null && _posts.length >= _postCount!,
|
||||||
onFetchData: _fetchPosts,
|
onFetchData: _fetchPosts,
|
||||||
itemBuilder: (context, idx) {
|
itemBuilder: (context, idx) {
|
||||||
return PostItem(data: _posts[idx]);
|
return GestureDetector(
|
||||||
|
child: PostItem(data: _posts[idx]),
|
||||||
|
onTap: () {
|
||||||
|
GoRouter.of(context).pushNamed(
|
||||||
|
'postDetail',
|
||||||
|
pathParameters: {'slug': _posts[idx].id.toString()},
|
||||||
|
extra: _posts[idx],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) => const Divider(),
|
separatorBuilder: (context, index) => const Divider(),
|
||||||
)
|
)
|
||||||
|
102
lib/screens/post/post_detail.dart
Normal file
102
lib/screens/post/post_detail.dart
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
|
import 'package:surface/providers/sn_attachment.dart';
|
||||||
|
import 'package:surface/providers/sn_network.dart';
|
||||||
|
import 'package:surface/types/post.dart';
|
||||||
|
import 'package:surface/widgets/dialog.dart';
|
||||||
|
import 'package:surface/widgets/loading_indicator.dart';
|
||||||
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
|
import 'package:surface/widgets/post/post_item.dart';
|
||||||
|
|
||||||
|
class PostDetailScreen extends StatefulWidget {
|
||||||
|
final String slug;
|
||||||
|
final SnPost? preload;
|
||||||
|
const PostDetailScreen({
|
||||||
|
super.key,
|
||||||
|
required this.slug,
|
||||||
|
this.preload,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PostDetailScreen> createState() => _PostDetailScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PostDetailScreenState extends State<PostDetailScreen> {
|
||||||
|
bool _isBusy = false;
|
||||||
|
|
||||||
|
SnPost? _data;
|
||||||
|
|
||||||
|
void _fetchPost() async {
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final sn = context.read<SnNetworkProvider>();
|
||||||
|
final attach = context.read<SnAttachmentProvider>();
|
||||||
|
final resp = await sn.client.get('/cgi/co/posts/${widget.slug}');
|
||||||
|
if (!mounted) return;
|
||||||
|
final attachments = await attach.getMultiple(
|
||||||
|
resp.data['body']['attachments']?.cast<String>() ?? [],
|
||||||
|
);
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_data = SnPost.fromJson(resp.data).copyWith(
|
||||||
|
preload: SnPostPreload(
|
||||||
|
attachments: attachments,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
context.showErrorDialog(err);
|
||||||
|
} finally {
|
||||||
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (widget.preload != null) {
|
||||||
|
_data = widget.preload;
|
||||||
|
}
|
||||||
|
_fetchPost();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AppScaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: BackButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (GoRouter.of(context).canPop()) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
GoRouter.of(context).replaceNamed('explore');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
flexibleSpace: Column(
|
||||||
|
children: [
|
||||||
|
Text(_data?.body['title'] ?? 'postNoun'.tr())
|
||||||
|
.textStyle(Theme.of(context).textTheme.titleLarge!)
|
||||||
|
.textColor(Colors.white),
|
||||||
|
Text('postDetail')
|
||||||
|
.tr()
|
||||||
|
.textColor(Colors.white.withAlpha((255 * 0.9).round())),
|
||||||
|
],
|
||||||
|
).padding(top: math.max(MediaQuery.of(context).padding.top, 8)),
|
||||||
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
LoadingIndicator(isActive: _isBusy),
|
||||||
|
if (_data != null) PostItem(data: _data!),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||||
@ -276,14 +278,14 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
|||||||
),
|
),
|
||||||
flexibleSpace: Column(
|
flexibleSpace: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(_title ?? 'Untitled')
|
Text(_title ?? 'untitled'.tr())
|
||||||
.textStyle(Theme.of(context).textTheme.titleLarge!)
|
.textStyle(Theme.of(context).textTheme.titleLarge!)
|
||||||
.textColor(Colors.white),
|
.textColor(Colors.white),
|
||||||
Text(_kTitleMap[widget.mode]!)
|
Text(_kTitleMap[widget.mode]!)
|
||||||
.tr()
|
.tr()
|
||||||
.textColor(Colors.white.withAlpha((255 * 0.9).round())),
|
.textColor(Colors.white.withAlpha((255 * 0.9).round())),
|
||||||
],
|
],
|
||||||
).padding(top: MediaQuery.of(context).padding.top),
|
).padding(top: math.max(MediaQuery.of(context).padding.top, 8)),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Symbols.tune),
|
icon: const Icon(Symbols.tune),
|
||||||
|
@ -70,7 +70,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
.bold()
|
.bold()
|
||||||
.fontSize(17)
|
.fontSize(17)
|
||||||
.tr()
|
.tr()
|
||||||
.padding(horizontal: 20),
|
.padding(horizontal: 20, bottom: 4),
|
||||||
if (!kIsWeb)
|
if (!kIsWeb)
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('settingsBackgroundImage').tr(),
|
title: Text('settingsBackgroundImage').tr(),
|
||||||
@ -141,7 +141,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
.bold()
|
.bold()
|
||||||
.fontSize(17)
|
.fontSize(17)
|
||||||
.tr()
|
.tr()
|
||||||
.padding(horizontal: 20),
|
.padding(horizontal: 20, bottom: 4),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _serverUrlController,
|
controller: _serverUrlController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
@ -23,15 +23,22 @@ Future<ThemeData> createAppTheme(
|
|||||||
}) async {
|
}) async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
final colorScheme = ColorScheme.fromSeed(
|
||||||
|
seedColor: Colors.indigo,
|
||||||
|
brightness: brightness,
|
||||||
|
);
|
||||||
|
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
useMaterial3:
|
useMaterial3:
|
||||||
useMaterial3 ?? (prefs.getBool(kMaterialYouToggleStoreKey) ?? false),
|
useMaterial3 ?? (prefs.getBool(kMaterialYouToggleStoreKey) ?? false),
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: colorScheme,
|
||||||
seedColor: Colors.indigo,
|
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
|
iconTheme: IconThemeData(
|
||||||
|
fill: 0,
|
||||||
|
weight: 400,
|
||||||
|
opticalSize: 20,
|
||||||
|
color: colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
brightness: brightness,
|
|
||||||
iconTheme: const IconThemeData(fill: 0, weight: 400, opticalSize: 20),
|
|
||||||
scaffoldBackgroundColor: Colors.transparent,
|
scaffoldBackgroundColor: Colors.transparent,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.10.1"
|
version: "4.10.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
|
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
|
||||||
|
@ -30,8 +30,6 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
collection:
|
|
||||||
sdk: flutter
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
@ -74,6 +72,7 @@ dependencies:
|
|||||||
photo_view: ^0.15.0
|
photo_view: ^0.15.0
|
||||||
shared_preferences: ^2.3.3
|
shared_preferences: ^2.3.3
|
||||||
path_provider: ^2.1.5
|
path_provider: ^2.1.5
|
||||||
|
collection: ^1.19.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user