【发布时间】:2021-08-06 09:31:09
【问题描述】:
我有一页叫registerUser.dart 示例代码如下:
import 'package:http/http.dart' as http;
import 'package:login/URL/urls.dart';
class UserRegister extends StatefulWidget {
const UserRegister({Key key}) : super(key: key);
@override
_UserRegisterState createState() => _UserRegisterState();
}
class _UserRegisterState extends State<UserRegister> {
GlobalKey<FormState> key = GlobalKey<FormState>();
TextEditingController firstName = TextEditingController();
TextEditingController LastName = TextEditingController();
TextEditingController email = TextEditingController();
// var listOFUrl =listOFallUrl(firstName,this.LastName,this.email);
final surj =new listOFallUrl.myUrlConstructor(firstName.text);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Lab Work"),
),
body: SingleChildScrollView(
child: Form(
key: key,
child: Column(
children: <Widget>[
TextFormField(
controller: firstName,
decoration: InputDecoration(labelText: 'Item Name'),
validator: (value) =>
value.isEmpty ? 'this field cannot be empty' : null,
),
TextFormField(
decoration: InputDecoration(labelText: 'Item Price'),
validator: (value) =>
value.isEmpty ? 'this field cannot be empty' : null,
controller: LastName,
),
TextFormField(
controller: email,
decoration: InputDecoration(labelText: 'Item Description'),
validator: (value) =>
value.isEmpty ? 'this field cannot be empty' : null,
),
ElevatedButton(
onPressed: () {
if (key.currentState.validate()) {
// putProduct();
print("record inserted");
}
},
child: Text('Save'),
)
],
),
),
));
}
}
并希望在firstName、lastName 和email TextEditingController 上方使用名为urls.dart 的页面。怎么可能呢?我尝试使用listOFallUrl 类的参考变量传递textEditorController,但没有成功。
import 'package:http/http.dart' as http;
class listOFallUrl{
listOFallUrl(TextEditingController firtname){}
listOFallUrl.myUrlConstructor(){
print("this is example");
}
void URL(TextEditingController firtname){
}
} ```
【问题讨论】: