Skip to content

Instantly share code, notes, and snippets.

@Laiba4343
Created June 3, 2025 22:35
Show Gist options
  • Save Laiba4343/ea685f3069c0098dac04cf8bdb9df644 to your computer and use it in GitHub Desktop.
Save Laiba4343/ea685f3069c0098dac04cf8bdb9df644 to your computer and use it in GitHub Desktop.
campuscare
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:io';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'dart:async';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'CampusCare',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Color(0xFF2196F3)),
primaryColor: Color(0xFF2196F3),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF2196F3),
foregroundColor: Colors.white,
),
scaffoldBackgroundColor: Colors.white,
textTheme: ThemeData.light().textTheme.apply(
bodyColor: Colors.black,
displayColor: Colors.black,
),
),
home: const SplashScreen(),
);
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
Future.delayed(const Duration(seconds: 3), () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const CampusCareWebView()),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Image.asset(
'assets/splash.png',
fit: BoxFit.contain,
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.8,
),
),
),
);
}
}
class CampusCareWebView extends StatefulWidget {
const CampusCareWebView({super.key});
@override
State<CampusCareWebView> createState() => _CampusCareWebViewState();
}
class _CampusCareWebViewState extends State<CampusCareWebView> {
late final WebViewController _controller;
int _currentIndex = 0;
final List<String> _urls = [
'https://sargodha-student-central.lovable.app/',
'https://sargodha-student-central.lovable.app/timetable',
'https://sargodha-student-central.lovable.app/resources',
'https://sargodha-student-central.lovable.app/support',
'https://sargodha-student-central.lovable.app/events',
];
@override
void initState() {
super.initState();
_controller =
WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onPageFinished: (url) {
_injectFixes(); // Reinject fixes on each page load
},
),
)
..loadRequest(Uri.parse(_urls[_currentIndex]));
}
void _injectFixes() {
_controller.runJavaScript('''
// 🚫 Remove the Lovable iframe(s)
document.querySelectorAll("iframe").forEach(el => el.remove());
// ❌ Remove the Lovable badge close button and its parent <a>
const closeBtn = document.querySelector("#lovable-badge-close");
if (closeBtn) {
const parentA = closeBtn.closest("a");
if (parentA) parentA.remove();
else closeBtn.remove();
}
// 🧹 Remove any element containing "Lovable" text
Array.from(document.querySelectorAll("body *")).forEach(el => {
if (el.innerText?.includes("Lovable")) el.remove();
});
// πŸ“± Fix the viewport settings without affecting layout
let viewport = document.querySelector('meta[name=viewport]');
if (!viewport) {
viewport = document.createElement('meta');
viewport.name = 'viewport';
document.head.appendChild(viewport);
}
viewport.content = 'width=device-width, initial-scale=1.0';
// πŸ” Force zoom to 100%
document.body.style.zoom = '100%';
// πŸ›  Restore touch behavior but allow scrolling
const style = document.createElement('style');
style.innerHTML = 'body { overscroll-behavior: auto; touch-action: auto; }';
document.head.appendChild(style);
''');
}
void _onTabTapped(int index) {
setState(() {
_currentIndex = index;
_controller.loadRequest(Uri.parse(_urls[index]));
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.school, size: 28, color: Colors.white),
const SizedBox(width: 8),
Text(
'CampusCare',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.white,
),
),
],
),
backgroundColor: const Color(0xFF2196F3),
elevation: 0,
),
body: SafeArea(
child: Column(
children: [Expanded(child: WebViewWidget(controller: _controller))],
),
),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Color(0xFF2196F3),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white70,
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
onTap: _onTabTapped,
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(
icon: Icon(Icons.schedule),
label: 'Timetable',
),
BottomNavigationBarItem(
icon: Icon(Icons.menu_book),
label: 'Resources',
),
BottomNavigationBarItem(
icon: Icon(Icons.group),
label: 'Peer Support',
),
BottomNavigationBarItem(icon: Icon(Icons.event), label: 'Events'),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment