This repository has been archived on 2025-06-12. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Temperaturdecke/lib/main.dart
2024-05-17 23:46:30 +02:00

113 lines
3.4 KiB
Dart

import 'package:drift/drift.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:temperaturdecke/database.dart';
import 'package:temperaturdecke/screens/day.dart';
import 'package:temperaturdecke/screens/overview.dart';
import 'package:temperaturdecke/screens/settings.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:temperaturdecke/screens/wool.dart';
void main() async {
runApp(Provider<AppDatabase>(
create: (context) => AppDatabase(),
child: MyApp(),
dispose: (context, db) => db.close(),
));
WidgetsFlutterBinding.ensureInitialized();
}
class MyApp extends StatefulWidget {
MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int currentPageIndex = 0;
List screens = [
dayScreen(),
OverviewScreen(),
WoolScreen(),
SettingsScreen(),
];
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
ColorScheme lightColorScheme;
ColorScheme darkColorScheme;
if (lightDynamic != null && darkDynamic != null) {
// On Android S+ devices, use the provided dynamic color scheme.
// (Recommended) Harmonize the dynamic color scheme' built-in semantic colors.
lightColorScheme = lightDynamic.harmonized();
// Repeat for the dark color scheme.
darkColorScheme = darkDynamic.harmonized();
} else {
// Otherwise, use fallback schemes.
lightColorScheme = ColorScheme.fromSeed(
seedColor: Colors.blue,
);
darkColorScheme = ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.dark,
);
}
return MaterialApp(
theme: ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
title: 'Flutter Demo',
home: Scaffold(
body: AnimatedSwitcher(
duration: Duration(milliseconds: 200),
child: screens[currentPageIndex],
),
bottomNavigationBar: NavigationBar(
onDestinationSelected: (int index) {
print(currentPageIndex);
setState(() {
currentPageIndex = index;
});
},
selectedIndex: currentPageIndex,
destinations: const <Widget>[
NavigationDestination(
icon: Icon(Icons.sunny),
label: 'Tag',
),
NavigationDestination(
icon: Icon(Icons.list),
label: 'Übersicht',
),
NavigationDestination(
icon: Icon(Icons.circle),
label: 'Wolle',
),
NavigationDestination(
icon: Icon(Icons.settings),
label: 'Einstellungen',
),
],
),
),
);
});
}
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return dayScreen();
}