0

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"),
        ],
      ),
    );
  }
}

jw-dev
  • 1
  • 1

1 Answers1

0

You cannot open a debug app from your phone without it being plugged to your machine, that is a standard from Apple.

If you build it in release mode the best way to test is on your device (without it being plugged to your Mac) is to upload it to the AppStore Connect using the Transporter app. This will make your .ipa available in TestFlight.

For further information on the subject, check out this very detailed answer How do I run/test my Flutter app on a real device?

In any case you will need a developer account to produce the required certificates.

Colin Lazarini
  • 754
  • 4
  • 14
  • I know that you can't use a debug app without it being connected to a machine. How ever I changed the build configuration under the Scheme to "release". Now I can open the app after I disconnect my phone from the machine but the app won't show properly if I close and reopen the app. I made a YouTube video to show you: [YouTube Video Link](https://youtube.com/shorts/kG4d_ZyonVo?feature=share) – jw-dev Jun 12 '23 at 14:34