- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从用户那里获取 4 个输入以显示最小值、最大值并显示中间值 1 和中间值 2。现在的事实是,每当我尝试输入以对其执行操作以显示我的答案时。它显示“类型'TextEditingController'不是类型转换中类型'int'的子类型”。我使用 int.parse() 方法将其转换为字符串,但仍然没有用。这是我的代码:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:inputtext/convert.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int min, max, mid1, mid2, temp;
String output = '';
TextEditingController inputvalue1 = new TextEditingController();
TextEditingController inputvalue2 = new TextEditingController();
TextEditingController inputvalue3 = new TextEditingController();
TextEditingController inputvalue4 = new TextEditingController();
// @override
// void initState() {
// super.initState();
// inputvalues = new TextEditingController();
// inputvalues.text = '';
// }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'InputValue',
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
color: Colors.blueAccent[50],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 5,
),
Flexible(
flex: 1,
child: TextFormField(
autofocus: true,
controller: inputvalue1,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
autofocus: true,
controller: inputvalue2,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
autofocus: true,
controller: inputvalue3,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
//validator: (),
autofocus: true,
controller: inputvalue4,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
RaisedButton(
child: Text(
'Submit',
style: TextStyle(color: Colors.blue),
),
onPressed: () {
comp();
},
),
SizedBox(
height: 10,
),
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Convert()),
);
},
child: Text(
'Next',
style: TextStyle(color: Colors.blue),
),
),
//Text(result),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
return showDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return SimpleDialog(
title: Text("Values"),
// content: TextField(controller: inputvalue1),
children: <Widget>[
SimpleDialogOption(
onPressed: () {
setState(() {
print('Minimum Value= ' + min.toString());
});
},
),
],
);
},
);
// setState(() {
// print('Minimum Value=' + min.toString());
// print('Maximum Value=' + max.toString());
// print('Mid1=' + mid1.toString());
// print('Mid2 =' + mid2.toString());
// });
// Navigator.of(context).pop();
},
),
);
}
void comp() {
if (inputvalue1.text.toString() == inputvalue2.text.toString() ||
inputvalue1.text.toString() == inputvalue3.text.toString() ||
inputvalue1.text.toString() == inputvalue4.text.toString()) {
print('Please input different number');
} else if (inputvalue2.text.toString() == inputvalue3.text.toString() ||
inputvalue2.text.toString() == inputvalue4.text.toString()) {
print('Please input different number');
} else if (inputvalue3.text.toString() == inputvalue4.text.toString()) {
print('Please enter differet vlaues');
}
//Finding minimum value
if (int.parse(inputvalue1.text) <= int.parse(inputvalue2.text) &&
int.parse(inputvalue1.text) <= int.parse(inputvalue3.text) &&
int.parse(inputvalue1.text) <= int.parse(inputvalue4.text)) {
min = inputvalue1 as int;
} else if (int.parse(inputvalue2.text) <= int.parse(inputvalue3.text) &&
int.parse(inputvalue2.text) <= int.parse(inputvalue4.text)) {
min = inputvalue2 as int;
} else if (int.parse(inputvalue3.text) <= int.parse(inputvalue4.text)) {
min = inputvalue3 as int;
} else {
min = inputvalue4 as int;
}
//finding maximum number
if (int.parse(inputvalue1.text) >= int.parse(inputvalue2.text) &&
int.parse(inputvalue1.text) >= int.parse(inputvalue2.text) &&
int.parse(inputvalue1.text) >= int.parse(inputvalue3.text) &&
int.parse(inputvalue1.text) >= int.parse(inputvalue4.text)) {
max = inputvalue1 as int;
} else if (int.parse(inputvalue2.text) >= int.parse(inputvalue3.text) &&
int.parse(inputvalue2.text) >= int.parse(inputvalue4.text)) {
max = inputvalue2 as int;
} else if (int.parse(inputvalue3.text) >= int.parse(inputvalue4.text)) {
max = inputvalue3 as int;
} else {
max = inputvalue4 as int;
}
//finding mid1
if (int.parse(inputvalue1.text) != min &&
int.parse(inputvalue1.text) != max) {
mid1 = inputvalue1 as int;
} else if (int.parse(inputvalue2.text) != min &&
int.parse(inputvalue2.text) != max) {
mid1 = inputvalue2 as int;
} else if (int.parse(inputvalue3.text) != min &&
int.parse(inputvalue3.text) != max) {
mid1 = inputvalue3 as int;
} else if (int.parse(inputvalue4.text) != min &&
int.parse(inputvalue4.text) != max) {
mid1 = inputvalue4 as int;
}
//finding mid2
if (int.parse(inputvalue1.text) != mid1 &&
int.parse(inputvalue1.text) != min &&
int.parse(inputvalue1.text) != max) {
mid2 = inputvalue1 as int;
} else if (int.parse(inputvalue2.text) != mid1 &&
int.parse(inputvalue2.text) != min &&
int.parse(inputvalue2.text) != max) {
mid2 = inputvalue2 as int;
} else if (int.parse(inputvalue3.text) != mid1 &&
int.parse(inputvalue3.text) != min &&
int.parse(inputvalue3.text) != max) {
mid2 = inputvalue3 as int;
} else if (int.parse(inputvalue4.text) != mid1 &&
int.parse(inputvalue4.text) != min &&
int.parse(inputvalue4.text) != max) {
mid2 = inputvalue4 as int;
}
if (mid1 > mid2) {
temp = mid1;
mid1 = mid2;
mid2 = temp;
}
}
}
感谢您的回答
错误日志
══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
I/flutter ( 5462): The following assertion was thrown while dispatching notifications for FocusNode:
I/flutter ( 5462): RenderBox was not laid out: RenderEditable#cd6b6 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5462): 'package:flutter/src/rendering/box.dart':
I/flutter ( 5462): Failed assertion: line 1687 pos 12: 'hasSize'
I/flutter ( 5462):
I/flutter ( 5462): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 5462): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 5462): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 5462): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 5462):
I/flutter ( 5462): When the exception was thrown, this was the stack:
I/flutter ( 5462): #2 RenderBox.size
package:flutter/…/rendering/box.dart:1687
I/flutter ( 5462): #3 EditableTextState._updateSizeAndTransform
package:flutter/…/widgets/editable_text.dart:1729
I/flutter ( 5462): #4 EditableTextState._openInputConnection
package:flutter/…/widgets/editable_text.dart:1415
I/flutter ( 5462): #5 EditableTextState._openOrCloseInputConnectionIfNeeded
package:flutter/…/widgets/editable_text.dart:1441
I/flutter ( 5462): #6 EditableTextState._handleFocusChanged
package:flutter/…/widgets/editable_text.dart:1707
I/flutter ( 5462): #7 ChangeNotifier.notifyListeners
package:flutter/…/foundation/change_notifier.dart:206
I/flutter ( 5462): #8 FocusNode._notify
package:flutter/…/widgets/focus_manager.dart:825
I/flutter ( 5462): #9 FocusManager._applyFocusChange
package:flutter/…/widgets/focus_manager.dart:1456
I/flutter ( 5462): (elided 12 frames from class _AssertionError and package dart:async)
I/flutter ( 5462):
I/flutter ( 5462): The FocusNode sending notification was:
I/flutter ( 5462): FocusNode#bbc92
I/flutter ( 5462): ════════════════════════════════════════════════════════════════════════════════════════════════════
Exception caught by gesture ═══════════════════════════════════════════
The following _CastError was thrown while handling a gesture:
type 'TextEditingController' is not a subtype of type 'int' in type cast
When the exception was thrown, this was the stack
#0 _HomePageState.comp
package:inputtext/homepage.dart:213
#1 _HomePageState.build.<anonymous closure>
package:inputtext/homepage.dart:133
#2 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:706
#3 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:789
#4 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:182
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#e5be9
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(212.6, 351.2)
finalLocalPosition: Offset(50.8, 5.9)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by gesture ═══════════════════════════════════════════
type 'TextEditingController' is not a subtype of type 'int' in type cast
════════════════════════════════════════════════════════════════════════════════
Reloaded 2 of 480 libraries in 585ms.
Reloaded 2 of 480 libraries in 262ms.
════════ Exception caught by gesture ═══════════════════════════════════════════
The following _CastError was thrown while handling a gesture:
type 'TextEditingController' is not a subtype of type 'int' in type cast
When the exception was thrown, this was the stack
#0 _HomePageState.comp
package:inputtext/homepage.dart:210
#1 _HomePageState.build.<anonymous closure>
package:inputtext/homepage.dart:133
#2 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:706
#3 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:789
#4 GestureRecognizer.invokeCallback package:flutter/…/gestures/recognizer.dart:182
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#e5be9
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(201.1, 369.1)
finalLocalPosition: Offset(39.4, 23.8)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════
Reloaded 2 of 480 libraries in 2,487ms.
════════ Exception caught by gesture ═══════════════════════════════════════════
The following _CastError was thrown while handling a gesture:
type 'TextEditingController' is not a subtype of type 'int' in type cast
When the exception was thrown, this was the stack
#0 _HomePageState.comp
package:inputtext/homepage.dart:210
#1 _HomePageState.build.<anonymous closure>
package:inputtext/homepage.dart:133
#2 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:706
#3 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:789
#4 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:182
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#e5be9
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(220.2, 368.0)
finalLocalPosition: Offset(58.5, 22.6)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by gesture ═══════════════════════════════════════════
type 'TextEditingController' is not a subtype of type 'int' in type cast
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by gesture ═══════════════════════════════════════════
type 'TextEditingController' is not a subtype of type 'int' in type cast
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by gesture ═══════════════════════════════════════════
type 'TextEditingController' is not a subtype of type 'int' in type cast
最佳答案
只需检查下面的示例
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(HomePage());
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int min, max, mid1, mid2, temp;
String output = '';
TextEditingController inputvalue1 = new TextEditingController();
TextEditingController inputvalue2 = new TextEditingController();
TextEditingController inputvalue3 = new TextEditingController();
TextEditingController inputvalue4 = new TextEditingController();
// @override
// void initState() {
// super.initState();
// inputvalues = new TextEditingController();
// inputvalues.text = '';
// }
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(
'InputValue',
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
color: Colors.blueAccent[50],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 5,
),
Flexible(
flex: 1,
child: TextFormField(
autofocus: true,
controller: inputvalue1,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
autofocus: true,
controller: inputvalue2,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
autofocus: true,
controller: inputvalue3,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
Center(
child: TextFormField(
//validator: (),
autofocus: true,
controller: inputvalue4,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hoverColor: Colors.blueGrey,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
),
labelText: 'Enter Values',
),
),
),
SizedBox(height: 10),
RaisedButton(
child: Text(
'Submit',
style: TextStyle(color: Colors.blue),
),
onPressed: () {
comp();
},
),
SizedBox(
height: 10,
),
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Convert()),
);
},
child: Text(
'Next',
style: TextStyle(color: Colors.blue),
),
),
//Text(result),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
return showDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return SimpleDialog(
title: Text("Values"),
// content: TextField(controller: inputvalue1),
children: <Widget>[
SimpleDialogOption(
onPressed: () {
setState(() {
print('Minimum Value= ' + min.toString());
});
},
),
],
);
},
);
// setState(() {
// print('Minimum Value=' + min.toString());
// print('Maximum Value=' + max.toString());
// print('Mid1=' + mid1.toString());
// print('Mid2 =' + mid2.toString());
// });
// Navigator.of(context).pop();
},
),
),
);
}
void comp() {
int value1 =int.parse(inputvalue1.text);
int value2 =int.parse(inputvalue2.text);
int value3 = int.parse(inputvalue3.text);
int value4 =int.parse(inputvalue4.text);
if (value1 == value2||
value1 == value3||
value1 == value4) {
print('Please input different number');
} else if (value2 == value3 ||
value2 == value4) {
print('Please input different number');
} else if (value3== value4) {
print('Please enter differet vlaues');
}
//Finding minimum value
if (value1 <= value2 &&
value1 <= value3 &&
value1 <= value4) {
min = value1;
} else if (value2 <= value3 &&
value2 <= value4) {
min = value2;
} else if (value3 <= value4) {
min = value3;
} else {
min = value4;
}
print('Print the minimun number : $min');
//finding maximum number
if (value1 >= value2&&
value1 >= value2 &&
value1 >= value3 &&
value1 >= value4) {
max = value1;
} else if (value2 >= value3 &&
value2 >= value4) {
max = value2;
} else if (value3 >= value4) {
max = value3;
} else {
max = value4;
}
print('this is the max number : $max');
//finding mid1
if (value1 != min &&
value1!= max) {
mid1 = value1;
} else if (value2 != min &&
value2 != max) {
mid1 = value2;
} else if (value3!= min &&
value3 != max) {
mid1 = value3;
} else if (value4 != min &&
value4 != max) {
mid1 = value4;
}
print('This is the mid value $mid1');
//finding mid2
if (value1 != mid1 &&
value1 != min &&
value1 != max) {
mid2 = value1;
} else if (value2 != mid1 &&
value2 != min &&
value2!= max) {
mid2 =value2;
} else if (value3 != mid1 &&
value3 != min &&
value3 != max) {
mid2 = value3;
} else if (value4 != mid1 &&
value4 != min &&
value4 != max) {
mid2 = value4;
}
print('This is the mid 2 $mid2');
if (mid1 > mid2) {
temp = mid1;
mid1 = mid2;
mid2 = temp;
}
}
}
如果有用请告诉我
关于flutter - 类型 'TextEditingController' 不是类型转换中类型 'int' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60785956/
我正在尝试将一个字符串逐个字符地复制到另一个字符串中。目的不是复制整个字符串,而是复制其中的一部分(我稍后会为此做一些条件......) 但我不知道如何使用迭代器。 你能帮帮我吗? std::stri
我想将 void 指针转换为结构引用。 结构的最小示例: #include "Interface.h" class Foo { public: Foo() : mAddress((uint
这有点烦人:我有一个 div,它从窗口的左上角开始过渡,即使它位于文档的其他任何位置。我试过 usign -webkit-transform-origin 但没有成功,也许我用错了。有人可以帮助我吗?
假设,如果将 CSS3 转换/转换/动画分配给 DOM 元素,我是否可以检测到该过程的状态? 我想这样做的原因是因为我正在寻找类似过渡链的东西,例如,在前一个过渡之后运行一个过渡。 最佳答案 我在 h
最近我遇到了“不稳定”屏幕,这很可能是由 CSS 转换引起的。事实上,它只发生在 Chrome 浏览器 上(可能还有 Safari,因为一些人也报告了它)。知道如何让它看起来光滑吗?此外,您可能会注意
我正在开发一个简单的 slider ,它使用 CSS 过渡来为幻灯片设置动画。我用一些基本样式和一些 javascript 创建了一支笔 here .注意:由于 Codepen 使用 Prefixfr
我正在使用以下代码返回 IList: public IList FindCodesByCountry(string country) { var query =
如何设计像这样的操作: 计算 转化 翻译 例如:从“EUR”转换为“CNY”金额“100”。 这是 /convert?from=EUR&to=CNY&amount=100 RESTful 吗? 最佳答
我使用 jquery 组合了一个图像滚动器,如下所示 function rotateImages(whichHolder, start) { var images = $('#' +which
如何使用 CSS (-moz-transform) 更改一个如下所示的 div: 最佳答案 你可以看看Mozilla Developer Center .甚至还有例子。 但是,在我看来,您的具体示例不
我需要帮助我正在尝试在选中和未选中的汉堡菜单上实现动画。我能够为菜单设置动画,但我不知道如何在转换为 0 时为左菜单动画设置动画 &__menu { transform: translateX(
我正在为字典格式之间的转换而苦苦挣扎:我正在尝试将下面的项目数组转换为下面的结果数组。本质上是通过在项目第一个元素中查找重复项,然后仅在第一个参数不同时才将文件添加到结果集中。 var items:[
如果我有两个定义相同的结构,那么在它们之间进行转换的最佳方式是什么? struct A { int i; float f; }; struct B { int i; float f; }; void
我编写了一个 javascript 代码,可以将视口(viewport)从一个链接滑动到另一个链接。基本上一切正常,你怎么能在那里看到http://jsfiddle.net/DruwJ/8/ 我现在的
我需要将文件上传到 meteor ,对其进行一些图像处理(必要时进行图像转换,从图像生成缩略图),然后将其存储在外部图像存储服务器(s3)中。这应该尽可能快。 您对 nodejs 图像处理库有什么建议
刚开始接触KDB+,有一些问题很难从Q for Mortals中得到。 说,这里 http://code.kx.com/wiki/JB:QforMortals2/casting_and_enumera
我在这里的一个项目中使用 JSF 1.2 和 IceFaces 1.8。 我有一个页面,它基本上是一大堆浮点数字段的大编辑网格。这是通过 inputText 实现的页面上的字段指向具有原始值的值对象
ScnMatrix4 是一个 4x4 矩阵。我的问题是什么矩阵行对应于位置(ScnVector3),旋转(ScnVector4),比例(ScnVector3)。第 4 行是空的吗? 编辑: 我玩弄了
恐怕我是 Scala 新手: 我正在尝试根据一些简单的逻辑将 Map 转换为新 Map: val postVals = Map("test" -> "testing1", "test2" -> "te
输入: This is sample 1 This is sample 2 输出: ~COLOR~[Green]This is sample 1~COLOR~[Red]This is sam
我是一名优秀的程序员,十分优秀!