91 lines
2.4 KiB
Dart
91 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_database/firebase_database.dart';
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
import 'screens/realtime_data_screen.dart';
|
|
import 'screens/pump_schedule_screen.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
try {
|
|
if (kIsWeb) {
|
|
await Firebase.initializeApp(
|
|
options: const FirebaseOptions(
|
|
apiKey: "AIzaSyBCe-30GPJRp0p7psDH4t2D01WHPcSNIqQ",
|
|
authDomain: "apkrafi.firebaseapp.com",
|
|
databaseURL: "https://apkrafi-default-rtdb.firebaseio.com",
|
|
projectId: "apkrafi",
|
|
storageBucket: "apkrafi.appspot.com",
|
|
messagingSenderId: "121136047777",
|
|
appId: "1:121136047777:web:306ae9d0b88b7c33c432e0",
|
|
measurementId: "G-L31DDT24WJ"),
|
|
);
|
|
} else {
|
|
await Firebase.initializeApp();
|
|
}
|
|
print('Firebase initialized successfully');
|
|
} catch (e) {
|
|
print('Error initializing Firebase: $e');
|
|
}
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Smart Garden Monitor',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.green,
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
),
|
|
home: const MainScreen(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MainScreen extends StatefulWidget {
|
|
const MainScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<MainScreen> createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends State<MainScreen> {
|
|
int _selectedIndex = 0;
|
|
|
|
final List<Widget> _screens = [
|
|
const RealtimeDataScreen(),
|
|
const PumpScheduleScreen(),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: _screens[_selectedIndex],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _selectedIndex,
|
|
onTap: (index) {
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
},
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.sensors),
|
|
label: 'Sensor',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.schedule),
|
|
label: 'Jadwal',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|