I got this flutter app which I wanted to load on my real iPhone 14. I connected the phone with my MacBook Air with a M1 and launched it with Xcode. However if I run it with debug mode I can't open it when it's not connected to the MacBook. And If I run it with the release mode I can open it afterwards but sometimes I just see a blue screen (same blue as my primary color) and the bottom navigation bar. But when I close the app a few times and repopen it, after a few tries the app shows normally again.
This is my main.dart file
import 'package:flutter/material.dart';
import 'package:test/einstellungen.dart';
import 'package:test/favoriten.dart';
import 'package:test/homescreen.dart';
import 'package:test/utils/device_info.dart';
import 'package:test/utils/styles.dart';
// import 'package:test/widgets/favorits_test.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Trompeten Coach Home',
// generelles Styling
theme: ThemeData(
primaryColor: Styles.mainColor, // Hauptfarbe
scaffoldBackgroundColor: Styles.whiteColor, // Hintergrundfarbe
appBarTheme: AppBarTheme(
backgroundColor: Styles.mainColor,
elevation: 0,
toolbarHeight: DeviceInfo.getHeight(0), // Appbar wird eigentlich nicht angezeigt, aber die Farbe an Stellen wo kein Content hin kann schon
)),
home: const Main(), // ruft als Startseite "Main()" auf
);
}
}
// Grundgerüst (Skelett) der App
class Main extends StatefulWidget {
const Main({super.key});
@override
State<Main> createState() => _MainState();
}
class _MainState extends State<Main> {
// Funktion, welche aufgerufen wird, wenn die App gestartet wird
@override
void initState() {
super.initState();
// fügt die Daten im SharedPrefrences in die Liste "favoriten" hinzu
/* setState(() {
getFavorits();
}); */
}
// Liste mit den verschiedenen Seiten (Home, Favoriten und Einstellungen)
int selectedScreen = 0; // Anfangswert ist 0 => HomeScreen
static final List<Widget> screenOptions = <Widget>[
HomeScreen(),
HomeScreen(),
HomeScreen(),
];
// Funktion zum Ändern der aktuellen Seite durch klicken eines Icons in der BottomBar
void onItemTapped(int index) {
setState(() {
selectedScreen = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
// AppBar hinzufügen, um Platz, den man sonst nicht mit dem blauen Balken nicht füllen hätte können
appBar: AppBar(),
body: screenOptions[selectedScreen], // beim Body wird der Screen angezeigt, den man in der BottomBar angeglickt hat
// BottomBar
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Styles.whiteColor,
currentIndex: selectedScreen,
onTap:
onItemTapped, // Wenn man auf ein Icon klickt, wird der Screen gewechselt
showSelectedLabels: false,
showUnselectedLabels: false,
selectedItemColor: Styles.textColor,
unselectedItemColor: Styles.textColor,
type: BottomNavigationBarType.fixed,
// Items / Icons / Content
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
activeIcon: Icon(Icons.home),
label: "Home"),
BottomNavigationBarItem(
icon: Icon(Icons.favorite_outline),
activeIcon: Icon(Icons.favorite),
label: "Favoriten"),
BottomNavigationBarItem(
icon: Icon(Icons.settings_outlined),
activeIcon: Icon(Icons.settings),
label: "Einstellungen"),
],
),
);
}
}