voyagehandbook/lib/views/pageview.dart

79 lines
2.1 KiB
Dart
Raw Normal View History

2023-03-24 23:48:55 +01:00
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:voyagehandbook/api/wikimedia.dart';
import 'package:voyagehandbook/util/drawer.dart';
import 'package:voyagehandbook/util/render.dart';
2023-03-27 19:45:57 +02:00
import 'package:voyagehandbook/util/storage.dart';
2023-03-24 23:48:55 +01:00
/// Renders a single WikiVoyage article
class ArticleView extends StatefulWidget {
2023-03-27 19:45:57 +02:00
const ArticleView({super.key, required this.pageKey, required this.name});
2023-03-24 23:48:55 +01:00
final String pageKey;
2023-03-27 19:45:57 +02:00
final String name;
2023-03-24 23:48:55 +01:00
@override
State<ArticleView> createState() => _ArticleViewState();
}
class _ArticleViewState extends State<ArticleView> {
var _content = <Widget>[];
@override
2023-03-27 19:45:57 +02:00
didChangeDependencies() {
super.didChangeDependencies();
2023-03-24 23:48:55 +01:00
loadPage();
}
2023-03-27 19:45:57 +02:00
@override
void initState() {
super.initState();
addToRecents();
}
2023-03-24 23:48:55 +01:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: (kDebugMode)
? [
IconButton(
onPressed: () => loadPage(),
icon: const Icon(Icons.restart_alt))
]
: null),
drawer: genDrawer(0, context),
body: Center(
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width * 0.9,
child: SingleChildScrollView(
2023-03-27 19:45:57 +02:00
physics: const AlwaysScrollableScrollPhysics(),
2023-03-24 23:48:55 +01:00
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: _content,
),
),
),
),
);
}
void loadPage() async {
2023-03-27 19:45:57 +02:00
_content = [
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height,
child: renderFromPageHTML(
await WikiApi.getRawPage(widget.pageKey),
MediaQuery.of(context).size.height,
MediaQuery.of(context).size.width),
)
];
2023-03-24 23:48:55 +01:00
setState(() {});
}
2023-03-27 19:45:57 +02:00
void addToRecents() {
StorageAccess.addToRecents(widget.name, widget.pageKey);
}
2023-03-24 23:48:55 +01:00
}