kochkomplize/lib/main.dart

95 lines
2.3 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'startpage.dart';
import 'recipeformpage.dart';
import 'menu.dart';
import 'menu_content.dart';
import 'recipesoverview.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Kochkomplize',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.greenAccent),
useMaterial3: true,
),
home: const MyHomePage(title: 'Kochkomplize'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
MenuContent? _selectedMenuContent;
@override
void initState() {
super.initState();
_selectedMenuContent = Startpage(); // Initialisiere mit Startseite
}
void _onMenuItemSelected(String menuItem) {
setState(() {
switch (menuItem) {
case 'Meine Rezepte':
_selectedMenuContent = RecipesOverview();
break;
case 'Startseite':
_selectedMenuContent = Startpage();
break;
// case 'Texterkennung Bild':
// _selectedMenuContent = TextScan();
// break;
}
});
}
void _addRecipe() {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const Recipeformpage()),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
drawer: Menu(onMenuItemSelected: _onMenuItemSelected),
body: _selectedMenuContent?.build(context) ?? Container(),
floatingActionButton: _selectedMenuContent is RecipesOverview
? FloatingActionButton(
onPressed: _addRecipe,
tooltip: 'Rezept hinzufügen',
child: const Icon(Icons.add),
)
: null, // Kein Button für andere Seiten
);
}
}