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. 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