✨ Articles
This commit is contained in:
72
lib/screens/articles/article_detail.dart
Normal file
72
lib/screens/articles/article_detail.dart
Normal file
@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/articles.dart';
|
||||
import 'package:solian/providers/content/feed.dart';
|
||||
import 'package:solian/widgets/articles/article_item.dart';
|
||||
import 'package:solian/widgets/centered_container.dart';
|
||||
|
||||
class ArticleDetailScreen extends StatefulWidget {
|
||||
final String alias;
|
||||
|
||||
const ArticleDetailScreen({super.key, required this.alias});
|
||||
|
||||
@override
|
||||
State<ArticleDetailScreen> createState() => _ArticleDetailScreenState();
|
||||
}
|
||||
|
||||
class _ArticleDetailScreenState extends State<ArticleDetailScreen> {
|
||||
Article? item;
|
||||
|
||||
Future<Article?> getDetail() async {
|
||||
final FeedProvider provider = Get.find();
|
||||
|
||||
try {
|
||||
final resp = await provider.getArticle(widget.alias);
|
||||
item = Article.fromJson(resp.body);
|
||||
} catch (e) {
|
||||
context.showErrorDialog(e).then((_) => Navigator.pop(context));
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: FutureBuilder(
|
||||
future: getDetail(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data == null) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: CenteredContainer(
|
||||
child: ArticleItem(
|
||||
item: item!,
|
||||
isClickable: true,
|
||||
isFullDate: true,
|
||||
isFullContent: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: const Divider(thickness: 0.3, height: 1)
|
||||
.paddingOnly(top: 4),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: SizedBox(height: MediaQuery.of(context).padding.bottom),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -99,6 +99,8 @@ class _ArticlePublishScreenState extends State<ArticlePublishScreen> {
|
||||
|
||||
void syncWidget() {
|
||||
if (widget.edit != null) {
|
||||
_titleController.text = widget.edit!.title;
|
||||
_descriptionController.text = widget.edit!.description;
|
||||
_contentController.text = widget.edit!.content;
|
||||
_attachments = widget.edit!.attachments ?? List.empty();
|
||||
_isDraft = widget.edit!.isDraft ?? false;
|
@ -115,12 +115,12 @@ class FeedCreationButton extends StatelessWidget {
|
||||
itemBuilder: (BuildContext context) => [
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text('postCreate'.tr),
|
||||
title: Text('postEditor'.tr),
|
||||
leading: const Icon(Icons.article),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
onTap: () {
|
||||
AppRouter.instance.pushNamed('postCreate').then((val) {
|
||||
AppRouter.instance.pushNamed('postEditor').then((val) {
|
||||
if (val != null && onCreated != null) {
|
||||
onCreated!();
|
||||
}
|
||||
@ -129,12 +129,12 @@ class FeedCreationButton extends StatelessWidget {
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: ListTile(
|
||||
title: Text('articleCreate'.tr),
|
||||
title: Text('articleEditor'.tr),
|
||||
leading: const Icon(Icons.newspaper),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
onTap: () {
|
||||
AppRouter.instance.pushNamed('articleCreate').then((val) {
|
||||
AppRouter.instance.pushNamed('articleEditor').then((val) {
|
||||
if (val != null && onCreated != null) {
|
||||
onCreated!();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import 'package:solian/providers/content/feed.dart';
|
||||
import 'package:solian/providers/content/realm.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/screens/channel/channel_organize.dart';
|
||||
import 'package:solian/screens/posts/post_publish.dart';
|
||||
import 'package:solian/screens/posts/post_editor.dart';
|
||||
import 'package:solian/theme.dart';
|
||||
import 'package:solian/widgets/channel/channel_list.dart';
|
||||
import 'package:solian/widgets/posts/post_list.dart';
|
||||
@ -210,7 +210,7 @@ class _RealmPostListWidgetState extends State<RealmPostListWidget> {
|
||||
onTap: () {
|
||||
AppRouter.instance
|
||||
.pushNamed(
|
||||
'postCreate',
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(realm: widget.realm),
|
||||
)
|
||||
.then((value) {
|
||||
|
Reference in New Issue
Block a user