Flutter应用程序在iPhone上启动时崩溃

时间:2020-09-29 13:50:45

标签: ios iphone flutter dart

我用flutter编写了一个基本的计算器应用程序,并使用Xcode将其安装在我的iPhone上。 我构建了该应用程序,并在iPhone设置中信任了开发人员。但是,当我要打开应用程序时,背景屏幕模糊约2秒钟后崩溃。我不知道该应用程序在模拟器上运行有什么问题。我不知道代码是写得不好还是错过了一些配置步骤。对此有经验的人...

谢谢您的帮助。

设备日志/崩溃:

{
  "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,

颤振码

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

我在Xcode中有两个错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

enter image description here

进入xcode,并使用您自己的网站名称将捆绑包标识符更改为类似的内容。

com.mywebsitename.calculator