Browse Source

Merge pull request #230 from provokateurin/fix/news-article-webview-loading

neon: Fix news article loading in webview
pull/232/head
Kate 2 years ago committed by GitHub
parent
commit
ae3cd6cf3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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