JULIUS
JULIUS

Reputation: 121

Flutter application crashes at startup on iPhone

I wrote a basic calculator app with flutter and installed it on my iphone with Xcode. I builded the app and trusted the developer in the iPhone settings. But when I want to open the app it crashes after about 2 seconds of my background screen in blurry. I don't know what is wrong the app runs on the simulator. I don't know if the code is to bad written or if I missed some configuration steps. Has somebody experience with that...

Thank you for your help.

Device Log/ Crash:

{
  "crashReporterKey" : "771e2f68485128ac7de5b4f2d3a557289be32a15",
  "kernel" : "Darwin Kernel Version 20.0.0: Fri Aug 28 23:07:00 PDT 2020; root:xnu-7195.0.46~9\/RELEASE_ARM64_T8020",
  "product" : "iPhone11,2",
  "incident" : "E2C76AF9-8284-47F9-962E-FE6DB1D9AD19",
  "date" : "2020-09-28 21:24:44.54 +0200",
  "build" : "iPhone OS 14.0.1 (18A393)",
  "timeDelta" : 6,
  "memoryStatus" : {
  "compressorSize" : 29314,
  "compressions" : 1810481,
  "decompressions" : 1202975,
  "zoneMapCap" : 1454407680,
  "largestZone" : "APFS_4K_OBJS",
  "largestZoneSize" : 35880960,
  "pageSize" : 16384,
  "uncompressed" : 79755,
  "zoneMapSize" : 162873344,
  "memoryPages" : {
    "active" : 75993,
    "throttled" : 0,

Flutter Code

import 'package:flutter/material.dart';

void main() {
  runApp(Calculator());
}

class Calculator extends StatefulWidget {
  @override
  _CalculatorState createState() => _CalculatorState();
}

class _CalculatorState extends State<Calculator> {
  String _num1 = "";
  String _operator = "";
  String _num2 = "";
  String _show = "";
  bool _set_show_to_none = false;
  bool _isNum2 = false;


  void press_0_button_num1() {
    setState(() {
      _num1 += "0";
      _show += "0";
    });
  }


  void press_1_button_num1() {
    setState(() {
      _num1 += "1";
      _show += "1";
    });
  }

  void press_2_button_num1() {
    setState(() {
      _num1 += "2";
      _show += "2";
    });
  }

  void press_3_button_num1() {
    setState(() {
      _num1 += "3";
      _show += "3";
    });
  }

  void press_4_button_num1() {
    setState(() {
      _num1 += "4";
      _show += "4";
    });
  }

  void press_5_button_num1() {
    setState(() {
      _num1 += "5";
      _show += "5";
    });
  }

  void press_6_button_num1() {
    setState(() {
      _num1 += "6";
      _show += "6";
    });
  }

  void press_7_button_num1() {
    setState(() {
      _num1 += "7";
      _show += "7";
    });
  }

  void press_8_button_num1() {
    setState(() {
      _num1 += "8";
      _show += "8";
    });
  }

  void press_9_button_num1() {
    setState(() {
      _num1 += "9";
      _show += "9";
    });
  }



  void press_0_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "0";
      _show += "0";
      _set_show_to_none = false;
    });
  }

  void press_1_button_num2() {
    setState(() {
      if (_set_show_to_none){
       _show = "";}
      _num2 += "1";
      _show += "1";
      _set_show_to_none = false;
    });
  }

  void press_2_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "2";
      _show += "2";
      _set_show_to_none = false;
    });
  }

  void press_3_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "3";
      _show += "3";
      _set_show_to_none = false;
    });
  }

  void press_4_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "4";
      _show += "4";
      _set_show_to_none = false;
    });
  }

  void press_5_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "5";
      _show += "5";
      _set_show_to_none = false;
    });
  }

  void press_6_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "6";
      _show += "6";
      _set_show_to_none = false;
    });
  }

  void press_7_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "7";
      _show += "7";
      _set_show_to_none = false;
    });
  }

  void press_8_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "8";
      _show += "8";
      _set_show_to_none = false;
    });
  }

  void press_9_button_num2() {
    setState(() {
      if (_set_show_to_none){
        _show = "";}
      _num2 += "9";
      _show += "9";
      _set_show_to_none = false;
    });
  }


  void press_plus_button() {
    setState(() {
      _operator = "+";
      _show = "+";
      _set_show_to_none = true;
      _isNum2 = true;
    });
  }

  void press_minus_button() {
    setState(() {
      _operator = "-";
      _show = "-";
      _set_show_to_none = true;
      _isNum2 = true;
    });
  }

  void press_multiple_button() {
    setState(() {
      _operator = "*";
      _show = "*";
      _set_show_to_none = true;
      _isNum2 = true;
    });
  }

  void press_divided_button() {
    setState(() {
      _operator = "/";
      _show = "/";
      _set_show_to_none = true;
      _isNum2 = true;
    });
  }

  void press_ac_button() {
    setState(() {
      _num1 = "";
      _operator = "";
      _num2 = "";
      _show = "";
      _set_show_to_none = false;
      _isNum2 = false;
    });
  }


  void calculate() {
    setState(() {
      int num1int = int.tryParse(_num1);
      int num2int = int.tryParse(_num2);
      double num1do = num1int.toDouble();
      double num2do = num2int.toDouble();
      double result = 0;
      if (_operator == "+") {
        result = num1do + num2do;
      }
      else if (_operator == "-") {
        result = num1do - num2do;
      }
      else if (_operator == "*") {
        result = num1do * num2do;
      }
      else if (_operator == "/") {
        result = num1do / num2do;
      }
      RegExp regex = RegExp(r"([.]*0)(?!.*\d)");
      String result_output = result.toString().replaceAll(RegExp(r"([.]*0)(?!.*\d)"), "");
      _show = result_output;
    });
  }

    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
          body: Column(
            children: <Widget>[
              SizedBox(
                height: 98,
              ),
              Expanded(
                child: Align(
                  alignment: Alignment.centerRight,
                  child: Text(_show,
                      textAlign: TextAlign.right,
                      style: TextStyle(fontSize: 130)),
                ),
              ),
              Row(
                children: [
                  Container(
                    padding: const EdgeInsets.all(10.0),
                    child: SizedBox(
                      height: 70,
                      width: 150,
                      child: FloatingActionButton.extended(
                        elevation: 0.2,
                        onPressed: () {
                          press_ac_button();
                        },
                        label: Text("AC"),
                        isExtended: true,
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_1_button_num2();
                        } else {
                          press_1_button_num1();
                        }
                      },
                      child: Text("1"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_2_button_num2();
                        } else {
                          press_2_button_num1();
                        }
                      },
                      child: Text("2"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_3_button_num2();
                        } else {
                          press_3_button_num1();
                        }
                      },
                      child: Text("3"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        press_plus_button();
                      },
                      child: Text("+"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_4_button_num2();
                        } else {
                          press_4_button_num1();
                        }
                      },
                      child: Text("4"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_5_button_num2();
                        } else {
                          press_5_button_num2();
                        }
                      },
                      child: Text("5"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_6_button_num2();
                        } else {
                          press_6_button_num1();
                        }
                      },
                      child: Text("6"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        press_minus_button();
                      },
                      child: Text("-"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_7_button_num2();
                        } else {
                          press_7_button_num1();
                        }
                      },
                      child: Text("7"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_8_button_num2();
                        } else {
                          press_8_button_num1();
                        }
                      },
                      child: Text("8"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_9_button_num2();
                        } else {
                          press_9_button_num1();
                        }
                      },
                      child: Text("9"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        press_multiple_button();
                      },
                      child: Text("*"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 3,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 90,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        if (_isNum2) {
                          press_0_button_num2();
                        } else {
                          press_0_button_num1();
                        }
                      },
                      child: Text("0"),
                      isExtended: true,
                    ),
                  ),
                  SizedBox(
                    height: 75,
                    width: 180,//290
                    child: FloatingActionButton.extended(
                      elevation: 0.2,
                      onPressed: () {
                        calculate();
                      },
                      label: Text("="),
                      isExtended: true,
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {
                        press_divided_button();
                      },
                      child: Text("/"),
                    ),
                  )
                ],
              ),
              SizedBox(height: 47.5),
            ],
          ),
        ),
      );
    }
}

I have two errors in Xcode:

enter image description here

Upvotes: 0

Views: 207

Answers (1)

bm888
bm888

Reputation: 555

enter image description here

Go into xcode and change your Bundle Identifier to something like this using your own website name.

com.mywebsitename.calculator

Upvotes: 1

Related Questions