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. 46
      packages/neon/lib/src/apps/news/pages/article.dart

46
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, javascriptMode: JavascriptMode.unrestricted,
fit: StackFit.expand, onWebViewCreated: (final controller) async {
children: [ _webviewController = controller;
WebView( await controller.loadUrl(widget.url!);
javascriptMode: JavascriptMode.unrestricted, },
onWebViewCreated: (final controller) async { onPageFinished: (final _) async {
_webviewController = controller; await _startMarkAsReadTimer();
await controller.loadUrl(widget.url!); },
},
onPageStarted: (final _) {
setState(() {
_webviewLoading = true;
});
},
onPageFinished: (final _) async {
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