import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; class CalendarScreen extends StatefulWidget { const CalendarScreen({super.key}); @override State createState() => _CalendarScreenState(); } class _CalendarScreenState extends State { late final WebViewController _controller; bool _isLoading = true; bool _hasError = false; @override void initState() { super.initState(); _controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate( NavigationDelegate( onPageStarted: (_) => setState(() { _isLoading = true; _hasError = false; }), onPageFinished: (_) => setState(() => _isLoading = false), onWebResourceError: (error) => setState(() { _hasError = true; _isLoading = false; }), ), ) ..loadRequest(Uri.parse( 'https://calendar.google.com/calendar/u/0/embed?src=b9c267252d5be63d5cdc880be499885a88421eefd0e34e1392890daba0d8471e@group.calendar.google.com&ctz=Europe/Belgrade')); } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ WebViewWidget(controller: _controller), if (_isLoading) const Center(child: CircularProgressIndicator()), if (_hasError) Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( "Failed to load Google Calendar.", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 10), ElevatedButton( onPressed: () => _controller.reload(), child: const Text("Retry"), ), ], ), ), ], ), ); } }