gpt4 book ai didi

android - 在空上调用了 '_debugTypesAreRight'方法

转载 作者:行者123 更新时间:2023-12-03 04:45:01 24 4
gpt4 key购买 nike

我试图通过使用flutter来制作一个简单的计算器,但是当我运行它时;
有类似的错误。我在Google搜索了2个小时,但没有成功。

The tutorial that I used for making this app:https://www.youtube.com/watch?v=4NhLLmrB4I4

Exception caught by widgets library═══════════════════════════════════════════════════════ The followingNoSuchMethodError was thrown building Builder: The method'_debugTypesAreRight' was called on null. Receiver: null Triedcalling: _debugTypesAreRight(Instance of 'MyCalculator')


码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
* Simple calculator
*/

void main() => runApp(MyApp());

class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Calculator",
home: MyCalculator()
);
}

}

class MyCalculator extends StatefulWidget{
@override
State<StatefulWidget> createState() {
Calculator();
}

}

class Calculator extends State<MyCalculator>{

//TextFormField'e gelecek A ve B sayıları için conroller
final controller_numberA = TextEditingController();
final controller_numberB = TextEditingController();

final my_form_key = GlobalKey<FormState>();
String result = "";
String textToShow = "";
//toplam fonk.
void sum(){
//Formu kontrol et
//Seçilen işlem var ise
if(my_form_key.currentState.validate()){
int numberA = int.parse(controller_numberA.text);
int numberB = int.parse(controller_numberB.text);
int result = numberA + numberB;

setState(() {
//Yapılan işlemi gösterecek olan text
textToShow="$numberA + $numberB = $result";
});
}
}

void minus(){
//Formu kontrol et
//Seçilen işlem var ise
if(my_form_key.currentState.validate()){
int numberA = int.parse(controller_numberA.text);
int numberB = int.parse(controller_numberB.text);
int result = numberA - numberB;

setState(() {
//Yapılan işlemi gösterecek olan text
textToShow="$numberA - $numberB = $result";
});
}
}

void times(){
//Formu kontrol et
//Seçilen işlem var ise
if(my_form_key.currentState.validate()){
int numberA = int.parse(controller_numberA.text);
int numberB = int.parse(controller_numberB.text);
int result = numberA * numberB;

setState(() {
//Yapılan işlemi gösterecek olan text
textToShow="$numberA * $numberB = $result";
});
}
}

void divide(){
//Formu kontrol et
//Seçilen işlem var ise
if(my_form_key.currentState.validate()){
int numberA = int.parse(controller_numberA.text);
int numberB = int.parse(controller_numberB.text);
double result = numberA / numberB;

setState(() {
//Yapılan işlemi gösterecek olan text
textToShow="$numberA / $numberB = $result";
});
}
}

@override
Widget build(BuildContext context) {

//Tasarımı yapalım
return Scaffold(
body: Form(
key: my_form_key,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//2 tane TextFieldForm oluşturalım

TextFormField(
controller: controller_numberA,
validator: (value){
if(value.isEmpty) return "Please enter a number";
},
decoration: InputDecoration(hintText: "Enter a number"),
keyboardType: TextInputType.number),

TextFormField(
controller: controller_numberB,
validator: (value){
if(value.isEmpty) return "Please enter a number";
},
decoration: InputDecoration(hintText: "Enter a number"),
keyboardType: TextInputType.number),

//Sonuç TexField'i oluşturma
Text(textToShow,style: TextStyle(fontSize: 20.0),),

//Buton dizisi oluşturalım
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: sum,
child: Text('+'),
),
RaisedButton(
onPressed: minus,
child: Text('-'),
),
RaisedButton(
onPressed: times,
child: Text('*'),
),
RaisedButton(
onPressed: divide,
child: Text('/'),
),

],
)
],
),
)
);
}




}

最佳答案

再次检查您的createState,它应该是State<MyCalculator> createState并且应该返回Calculator(),但是您从不返回任何内容

class MyCalculator extends StatefulWidget{
@override
State<MyCalculator> createState() {
return Calculator();
}

}

关于android - 在空上调用了 '_debugTypesAreRight'方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62493494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com