147 lines
5.4 KiB
Dart
147 lines
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:app_links/app_links.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
// --- IMPORT APP COLORS ---
|
|
import 'constants/app_colors.dart';
|
|
// -------------------------
|
|
|
|
import 'services/mqtt_service.dart';
|
|
import 'screens/login_screen.dart';
|
|
import 'screens/register_screen.dart';
|
|
import 'screens/home_screen.dart';
|
|
import 'screens/analytics_screen.dart';
|
|
import 'screens/image_result_screen.dart';
|
|
import 'screens/change_password_screen.dart';
|
|
import 'screens/forgot_password_screen.dart';
|
|
import 'screens/splash_screen.dart';
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Supabase.initialize(
|
|
url: 'https://ddmhzzegejbsshihzext.supabase.co',
|
|
anonKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRkbWh6emVnZWpic3NoaWh6ZXh0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzcyMjIyNzAsImV4cCI6MjA5Mjc5ODI3MH0._r-viIQLMXuNNdg4tcn7sJTBO9QqSpSlF7hk43hu2Ks',
|
|
);
|
|
|
|
// Listener auth state — handle password recovery
|
|
Supabase.instance.client.auth.onAuthStateChange.listen((data) {
|
|
if (data.event == AuthChangeEvent.passwordRecovery) {
|
|
navigatorKey.currentState?.pushReplacementNamed(
|
|
'/change_password',
|
|
arguments: {'dari_reset': true},
|
|
);
|
|
}
|
|
});
|
|
|
|
// Handle deep link saat app sudah jalan
|
|
final appLinks = AppLinks();
|
|
appLinks.uriLinkStream.listen((uri) {
|
|
final uriStr = uri.toString();
|
|
if (uriStr.contains('reset-callback') ||
|
|
uriStr.contains('type=recovery')) {
|
|
// Supabase akan handle token otomatis via onAuthStateChange
|
|
debugPrint('Deep link diterima: $uriStr');
|
|
}
|
|
});
|
|
|
|
runApp(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (_) => MqttService()..connect()),
|
|
],
|
|
child: const MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
navigatorKey: navigatorKey,
|
|
title: 'Coffee IoT',
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
// --- KONFIGURASI TEMA LIGHT MODE (TERPUSAT) ---
|
|
theme: ThemeData(
|
|
useMaterial3: true,
|
|
brightness: Brightness.light,
|
|
scaffoldBackgroundColor: AppColors.background,
|
|
primaryColor: AppColors.primary,
|
|
|
|
// ColorScheme untuk warna dasar komponen Material (Tombol, Dialog, dll)
|
|
colorScheme: const ColorScheme.light(
|
|
primary: AppColors.primary,
|
|
secondary: AppColors.primary,
|
|
surface: AppColors.cardBg,
|
|
error: AppColors.error,
|
|
onPrimary: Colors.white,
|
|
onSurface: AppColors.textMain,
|
|
),
|
|
|
|
// Menerapkan Google Fonts (Poppins) dengan pewarnaan dari AppColors
|
|
textTheme: GoogleFonts.poppinsTextTheme(
|
|
ThemeData.light().textTheme,
|
|
).copyWith(
|
|
displayLarge: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.bold),
|
|
displayMedium: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.bold),
|
|
headlineLarge: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.bold),
|
|
headlineMedium: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.w600),
|
|
titleLarge: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.w600),
|
|
bodyLarge: GoogleFonts.poppins(color: AppColors.textMain),
|
|
bodyMedium: GoogleFonts.poppins(color: AppColors.textMain),
|
|
bodySmall: GoogleFonts.poppins(color: AppColors.textSecondary),
|
|
labelLarge: GoogleFonts.poppins(color: AppColors.textMain, fontWeight: FontWeight.w500),
|
|
),
|
|
|
|
// Tema AppBar Global (Biar transparan dan tulisannya otomatis ikut tema)
|
|
appBarTheme: AppBarTheme(
|
|
backgroundColor: AppColors.background,
|
|
elevation: 0,
|
|
centerTitle: true,
|
|
iconTheme: const IconThemeData(color: AppColors.textMain),
|
|
titleTextStyle: GoogleFonts.poppins(
|
|
color: AppColors.textMain,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
|
|
// Tema Card Global (Otomatis membulat dan punya bayangan halus)
|
|
cardTheme: CardThemeData(
|
|
color: AppColors.cardBg,
|
|
elevation: 2,
|
|
shadowColor: Colors.black.withValues(alpha: 0.05),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
),
|
|
|
|
// Tema Ikon Global
|
|
iconTheme: const IconThemeData(
|
|
color: AppColors.textMain,
|
|
),
|
|
),
|
|
// ----------------------------------------------
|
|
|
|
initialRoute: '/',
|
|
routes: {
|
|
'/': (context) => const SplashScreen(),
|
|
'/login': (context) => const LoginScreen(),
|
|
'/register': (context) => const RegisterScreen(),
|
|
'/home': (context) => const HomeScreen(),
|
|
'/analytics': (context) => const AnalyticsScreen(),
|
|
'/image_result': (context) => const ImageResultScreen(),
|
|
'/change_password': (context) => const ChangePasswordScreen(),
|
|
'/forgot_password': (context) => const ForgotPasswordScreen(),
|
|
},
|
|
);
|
|
}
|
|
} |