inou-mobile/lib/features/webview/webview_screen.dart

75 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../core/config.dart';
import '../../core/theme.dart';
/// WebView wrapper screen for inou web app
class WebViewScreen extends StatefulWidget {
const WebViewScreen({super.key});
@override
State<WebViewScreen> createState() => _WebViewScreenState();
}
class _WebViewScreenState extends State<WebViewScreen> {
late final WebViewController _controller;
bool _isLoading = true;
double _loadingProgress = 0;
@override
void initState() {
super.initState();
_initWebView();
}
void _initWebView() {
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(AppTheme.backgroundColor)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
setState(() {
_loadingProgress = progress / 100;
});
},
onPageStarted: (String url) {
setState(() {
_isLoading = true;
});
},
onPageFinished: (String url) {
setState(() {
_isLoading = false;
});
},
onWebResourceError: (WebResourceError error) {
debugPrint('WebView error: ${error.description}');
},
),
)
..loadRequest(Uri.parse(AppConfig.webAppUrl));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
WebViewWidget(controller: _controller),
if (_isLoading)
LinearProgressIndicator(
value: _loadingProgress,
backgroundColor: AppTheme.surfaceColor,
valueColor: const AlwaysStoppedAnimation<Color>(
AppTheme.primaryColor,
),
),
],
),
),
);
}
}