import 'package:flutter/cupertino.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:isekai_wiki/api/restbase/page.dart'; import 'package:isekai_wiki/components/safearea_builder.dart'; import 'package:isekai_wiki/components/wikipage_parser.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 createState() => _ArticlePageState(); } class _ArticlePageState extends State { bool loading = true; String title = ""; String description = ""; String content = ""; String contentHtml = ""; List categories = []; Future _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: SafeAreaBuilder( builder: (context, padding) => WikiPageParser( contentHtml: contentHtml, padding: padding, ), ), ); } }