voyagehandbook/lib/views/pageview.dart

56 lines
1.5 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';
/// Renders a single WikiVoyage article
class ArticleView extends StatefulWidget {
const ArticleView({super.key, required this.pageKey});
final String pageKey;
@override
State<ArticleView> createState() => _ArticleViewState();
}
class _ArticleViewState extends State<ArticleView> {
var _content = <Widget>[];
@override
initState() {
super.initState();
loadPage();
}
@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(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: _content,
),
),
),
),
);
}
void loadPage() async {
_content = renderFromPageHTML(await WikiApi.getRawPage(widget.pageKey));
setState(() {});
}
}