Browse Source

neon: Fix news article loading in webview

pull/230/head
jld3103 2 years ago
parent
commit
a07d8dc921
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 30
      packages/neon/lib/src/apps/news/pages/article.dart

30
packages/neon/lib/src/apps/news/pages/article.dart

@ -22,7 +22,6 @@ class NewsArticlePage extends StatefulWidget {
} }
class _NewsArticlePageState extends State<NewsArticlePage> { class _NewsArticlePageState extends State<NewsArticlePage> {
bool _webviewLoading = true;
WebViewController? _webviewController; WebViewController? _webviewController;
Timer? _markAsReadTimer; Timer? _markAsReadTimer;
@ -150,42 +149,15 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
], ],
), ),
body: widget.useWebView body: widget.useWebView
? Stack( ? WebView(
alignment: Alignment.center,
fit: StackFit.expand,
children: [
WebView(
javascriptMode: JavascriptMode.unrestricted, javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (final controller) async { onWebViewCreated: (final controller) async {
_webviewController = controller; _webviewController = controller;
await controller.loadUrl(widget.url!); await controller.loadUrl(widget.url!);
}, },
onPageStarted: (final _) {
setState(() {
_webviewLoading = true;
});
},
onPageFinished: (final _) async { onPageFinished: (final _) async {
await _startMarkAsReadTimer(); await _startMarkAsReadTimer();
setState(() {
_webviewLoading = false;
});
}, },
),
if (_webviewLoading) ...[
ColoredBox(
color: Theme.of(context).colorScheme.background,
child: Center(
child: LayoutBuilder(
builder: (final context, final constraints) => SizedBox(
width: constraints.maxWidth / 2,
child: const CustomLinearProgressIndicator(),
),
),
),
),
],
],
) )
: SingleChildScrollView( : SingleChildScrollView(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),

Loading…
Cancel
Save