165 lines
4.8 KiB
Dart
165 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:mom_kitchen/src/services/app_service.dart';
|
|
import 'package:mom_kitchen/src/services/orientation_service.dart';
|
|
import 'package:mom_kitchen/src/pages/home_page.dart';
|
|
import 'package:mom_kitchen/src/pages/theme_demo_page.dart';
|
|
import 'package:mom_kitchen/src/l10n/app_localizations.dart';
|
|
import 'package:mom_kitchen/src/standards/app_pages.dart';
|
|
import 'package:mom_kitchen/src/standards/page_validator.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await AppService.instance.init();
|
|
|
|
await OrientationService().lockPortrait();
|
|
|
|
AppPages.registerAll();
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final themeService = AppService.instance.theme;
|
|
|
|
return GetMaterialApp(
|
|
title: 'Mom\'s Kitchen',
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
theme: ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: themeService.primaryColor,
|
|
brightness: themeService.isDarkMode
|
|
? Brightness.dark
|
|
: Brightness.light,
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: themeService.primaryColor,
|
|
brightness: Brightness.dark,
|
|
),
|
|
),
|
|
themeMode: themeService.isDarkMode ? ThemeMode.dark : ThemeMode.light,
|
|
home: const HomePage(),
|
|
getPages: [
|
|
GetPage(
|
|
name: '/',
|
|
page: () {
|
|
AppPages.validateRoute('/');
|
|
return const HomePage();
|
|
},
|
|
),
|
|
GetPage(
|
|
name: '/theme',
|
|
page: () {
|
|
AppPages.validateRoute('/theme');
|
|
return const ThemeDemoPage();
|
|
},
|
|
),
|
|
],
|
|
onGenerateRoute: (settings) {
|
|
AppPages.validateRoute(settings.name ?? '');
|
|
return null;
|
|
},
|
|
navigatorObservers: [PageRoutingObserver()],
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomeScreen extends StatelessWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final themeService = AppService.instance.theme;
|
|
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: Text(l10n.appTitle),
|
|
backgroundColor: themeService.backgroundColor.withValues(alpha: 0.95),
|
|
),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(
|
|
l10n.welcomeMessage,
|
|
style: TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
color: themeService.textColor,
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
l10n.appDescription,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: themeService.textColor.withValues(alpha: 0.6),
|
|
),
|
|
),
|
|
const SizedBox(height: 40),
|
|
CupertinoButton.filled(
|
|
onPressed: () {
|
|
Get.to(const HomePage());
|
|
},
|
|
child: Text(l10n.getStarted),
|
|
),
|
|
const SizedBox(height: 20),
|
|
CupertinoButton.filled(
|
|
onPressed: () {
|
|
Get.to(const ThemeDemoPage());
|
|
},
|
|
child: Text(l10n.themeSettings),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class PageRoutingObserver extends NavigatorObserver {
|
|
@override
|
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
super.didPush(route, previousRoute);
|
|
_validateRoute(route.settings.name, previousRoute?.settings.name);
|
|
}
|
|
|
|
@override
|
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
super.didPop(route, previousRoute);
|
|
_validateRoute(previousRoute?.settings.name, route.settings.name);
|
|
}
|
|
|
|
@override
|
|
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
|
|
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
|
|
_validateRoute(newRoute?.settings.name, oldRoute?.settings.name);
|
|
}
|
|
|
|
void _validateRoute(String? routeName, String? previousRouteName) {
|
|
final currentRoute = routeName ?? previousRouteName;
|
|
if (currentRoute == null || currentRoute.isEmpty) return;
|
|
|
|
AppPages.validateRoute(currentRoute);
|
|
|
|
if (kDebugMode && navigator?.context != null) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
PageValidator.validate(navigator!.context, currentRoute);
|
|
});
|
|
}
|
|
}
|
|
}
|