import 'package:tower_app/constants.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:webview_flutter/webview_flutter.dart'; import 'dart:developer' as logDev; import '../../background.dart'; class DashboardScreen extends StatefulWidget { const DashboardScreen({Key? key}) : super(key: key); @override State createState() => _DashboardScreen(); } class _DashboardScreen extends State { WebViewController controller = WebViewController(); int user_id = 0; @override initState() { super.initState(); getUserID(); /* WidgetsBinding.instance.addPostFrameCallback((_) async { });*/ } getUserID() async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); await loading.show(); final SharedPreferences prefs = await SharedPreferences.getInstance(); user_id = prefs.getInt('user_id')!; logDev.log(user_id.toString(), name: "user id??"); setState(() { controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setBackgroundColor(const Color(0x00000000)) ..setNavigationDelegate( NavigationDelegate( onProgress: (int progress) { // Update loading bar. }, onPageStarted: (String url) {}, onPageFinished: (String url) {}, onWebResourceError: (WebResourceError error) {}, onNavigationRequest: (NavigationRequest request) { if (request.url.startsWith('https://www.youtube.com/')) { return NavigationDecision.prevent; } return NavigationDecision.navigate; }, ), ) ..loadRequest(Uri.parse(baseURL + "/dashboard/" + user_id.toString())); }); await loading.hide(); } @override Widget build(BuildContext context) { var size = MediaQuery.of(context).size; return Scaffold( body: Stack( children: [ Column( children: [ Stack( children: [ WavyHeader(), Container( margin: EdgeInsets.only( top: (size.height / 6) - 20), padding: EdgeInsets.fromLTRB(0, 5, 25, 5), child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( 'DASHBOARD CANVASING\t\t', maxLines: 1, style: GoogleFonts.luckiestGuy( fontSize: 28, color: Color(0xFF4858A7), fontStyle: FontStyle.italic, ), ), Image.asset( 'assets/icons/menu/ic_history.png', width: 40, height: 40, ), ], ) ), ], ), ], ), Container( margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10), child: WebViewWidget(controller: controller), ) ]), ); } } alertDialogFailedRetrievedData(BuildContext context) { Widget okButton = TextButton( child: Text("Refresh"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => DashboardScreen())); }, ); Widget noButton = TextButton( child: Text("Back"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pop(context); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Canvasing"), content: Text("Failed to Retrieve Data"), actions: [ noButton, okButton, ], ); // show the dialog showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return alert; }, ); }