forked from eatvio/eatvio_app
fix: issue-942, issue-967, fixed images positioning for blog posts
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
const _passKeyLoginPath = 'login_with_pass_key';
|
||||
const _contentReadyProgress = 40;
|
||||
|
||||
@visibleForTesting
|
||||
bool shouldHideGlossaryLoader({required String url, required int progress}) {
|
||||
if (url.isEmpty || url.contains(_passKeyLoginPath)) {
|
||||
return false;
|
||||
}
|
||||
return progress >= _contentReadyProgress;
|
||||
}
|
||||
|
||||
class GlossaryScreen extends StatefulWidget {
|
||||
const GlossaryScreen({super.key, required this.passKey});
|
||||
final String passKey;
|
||||
@@ -12,6 +25,8 @@ class GlossaryScreen extends StatefulWidget {
|
||||
|
||||
class _GlossaryScreenState extends State<GlossaryScreen> {
|
||||
late final WebViewController _controller;
|
||||
bool _isLoading = true;
|
||||
String _currentUrl = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -19,14 +34,47 @@ class _GlossaryScreenState extends State<GlossaryScreen> {
|
||||
|
||||
_controller = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onPageStarted: (url) {
|
||||
_currentUrl = url;
|
||||
},
|
||||
onProgress: (progress) {
|
||||
if (shouldHideGlossaryLoader(url: _currentUrl, progress: progress)) {
|
||||
_hideLoader();
|
||||
}
|
||||
},
|
||||
onPageFinished: (url) {
|
||||
if (shouldHideGlossaryLoader(url: url, progress: 100)) {
|
||||
_hideLoader();
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse('${sl<AppConfig>().baseUrl}/login_with_pass_key?id=${widget.passKey}'));
|
||||
}
|
||||
|
||||
void _hideLoader() {
|
||||
if (!_isLoading || !mounted) {
|
||||
return;
|
||||
}
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Глоссарий')),
|
||||
body: WebViewWidget(controller: _controller),
|
||||
body: Stack(
|
||||
children: [
|
||||
WebViewWidget(controller: _controller),
|
||||
if (_isLoading)
|
||||
ColoredBox(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: const SizedBox.expand(child: Loader()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user