You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.6 KiB
Dart
102 lines
2.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_html/flutter_html.dart';
|
|
import 'package:isekai_wiki/api/restbase/page.dart';
|
|
|
|
import '../components/isekai_nav_bar.dart';
|
|
import '../components/isekai_page_scaffold.dart';
|
|
import '../styles.dart';
|
|
|
|
class MinimumArticleData {
|
|
final String title;
|
|
final String? description;
|
|
final String? mainCategory;
|
|
final DateTime? updateTime;
|
|
|
|
MinimumArticleData(
|
|
{required this.title,
|
|
this.description,
|
|
this.mainCategory,
|
|
this.updateTime});
|
|
}
|
|
|
|
class ArticleCategoryData {
|
|
final String name;
|
|
final String identity;
|
|
|
|
ArticleCategoryData({required this.name, required this.identity});
|
|
}
|
|
|
|
class ArticlePage extends StatefulWidget {
|
|
final MinimumArticleData? initialArticleData;
|
|
final String? targetPage;
|
|
|
|
const ArticlePage({super.key, this.targetPage, this.initialArticleData});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _ArticlePageState();
|
|
}
|
|
|
|
class _ArticlePageState extends State<ArticlePage> {
|
|
bool loading = true;
|
|
String title = "";
|
|
String description = "";
|
|
String content = "";
|
|
String contentHtml = "";
|
|
List<String> categories = [];
|
|
|
|
Future<void> _loadPageContent() async {
|
|
if (widget.targetPage != null) {
|
|
var resContentHtml = await RestfulPageApi.getPageHtml(widget.targetPage!);
|
|
if (resContentHtml != null) {
|
|
setState(() {
|
|
contentHtml = resContentHtml;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
title = widget.initialArticleData?.title ?? "";
|
|
description = widget.initialArticleData?.description ?? "";
|
|
if (widget.initialArticleData?.mainCategory != null) {
|
|
categories.add(widget.initialArticleData!.mainCategory!);
|
|
}
|
|
super.initState();
|
|
_loadPageContent();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return IsekaiPageScaffold(
|
|
navigationBar: IsekaiNavigationBar(
|
|
middle: Text(title),
|
|
),
|
|
child: ListView(
|
|
children: <Widget>[
|
|
Container(
|
|
color: Styles.panelBackgroundColor,
|
|
child: SafeArea(
|
|
top: false,
|
|
bottom: false,
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (contentHtml == "") Text(description),
|
|
Html(
|
|
data: contentHtml,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|