我是新来的。我想将“<=”运算符应用于文本表单字段值,例如,我想检查必须从文本表单字段输入中获取的最小值和最大值。但它向我展示了运算符'<='没有为类'TextEditingController'定义。尝试定义运算符 '<='。这是我的源代码的样子:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int min, max, mid1, mid2, temp;
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>[
Center(
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: () {},
),
//Text(result),
],
),
),
);
}
void comp() {
if (inputvalue1 == inputvalue2 ||
inputvalue1 == inputvalue3 ||
inputvalue1 == inputvalue4) {
print('Please input different number');
} else if (inputvalue2 == inputvalue3 || inputvalue2 == inputvalue4) {
print('Please input different number');
} else if (inputvalue3 == inputvalue4) {
print('Please enter differet vlaues');
}
//Finding minimum value
if (inputvalue1 <= inputvalue2 &&
inputvalue1 <= inputvalue3 &&
inputvalue1 <= inputvalue4) {
min = inputvalue1 as int;
}
}
}